changed camouflaging scheme
This commit is contained in:
parent
235addc585
commit
98ccedecac
5 changed files with 235 additions and 319 deletions
|
@ -1456,14 +1456,7 @@ public:
|
|||
}
|
||||
|
||||
// Camo settings defaults
|
||||
CamoLevel camoLevel = CamoLevel::NONE;
|
||||
std::string camoWordStr = ZT_CAMO_DEFAULT_WORDSTR;
|
||||
uint32_t camoWord = 0;
|
||||
for (size_t i = 0; i < BYTES_IN_WORD; i++)
|
||||
{
|
||||
camoWord <<= 8;
|
||||
camoWord |= camoWordStr[i];
|
||||
}
|
||||
CamoAutoApplyBits camoAutoApply;
|
||||
CamoRelayRule relayRule = CamoRelayRule::LEAVE;
|
||||
KnownHostsMap knownHosts;
|
||||
|
||||
|
@ -1506,58 +1499,55 @@ public:
|
|||
if (camo.is_object())
|
||||
{
|
||||
CT("CAMO CONFIG SECTION FOUND");
|
||||
std::string camoLevelStr = OSUtils::jsonString(camo["level"], "none");
|
||||
std::transform(camoLevelStr.begin(), camoLevelStr.end(), camoLevelStr.begin(), [](unsigned char c)
|
||||
{
|
||||
return std::tolower(c);
|
||||
});
|
||||
CT("CAMO LEVEL SETTING: %s", camoLevelStr.c_str());
|
||||
|
||||
if (camoLevelStr == "node")
|
||||
{
|
||||
camoLevel = CamoLevel::NODE;
|
||||
}
|
||||
else if (camoLevelStr == "controller")
|
||||
{
|
||||
camoLevel = CamoLevel::CONTROLLER;
|
||||
}
|
||||
else if (camoLevelStr == "moon")
|
||||
{
|
||||
camoLevel = CamoLevel::MOON;
|
||||
}
|
||||
else if (camoLevelStr == "planet")
|
||||
{
|
||||
camoLevel = CamoLevel::PLANET;
|
||||
}
|
||||
|
||||
if (camo.contains("word"))
|
||||
{
|
||||
std::string temp = OSUtils::jsonString(camo["word"], ZT_CAMO_DEFAULT_WORDSTR);
|
||||
if (temp.substr(0, 2) == "0x")
|
||||
auto stringToClass = [](std::string &str) -> CamoClass {
|
||||
CamoClass result = CamoClass::NEVER;
|
||||
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c)
|
||||
{
|
||||
try
|
||||
{
|
||||
camoWord = std::stoul(temp.substr(2), nullptr, 16);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
return std::tolower(c);
|
||||
});
|
||||
if (str == "always")
|
||||
{
|
||||
CT("CAMO CLASS: ALWAYS");
|
||||
result = CamoClass::ALWAYS;
|
||||
}
|
||||
else if (str == "node")
|
||||
{
|
||||
CT("CAMO CLASS: NODE");
|
||||
result = CamoClass::NODE;
|
||||
}
|
||||
else if (str == "controller")
|
||||
{
|
||||
CT("CAMO CLASS: CONTROLLER");
|
||||
result = CamoClass::CONTROLLER;
|
||||
}
|
||||
else if (str == "moon")
|
||||
{
|
||||
CT("CAMO CLASS: MOON");
|
||||
result = CamoClass::MOON;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < BYTES_IN_WORD; i++)
|
||||
CT("CAMO CLASS: NEVER");
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
json &autoApply = camo["autoApply"];
|
||||
if (autoApply.is_array())
|
||||
{
|
||||
CT("AUTO APPLY SETTING FOUND");
|
||||
for (const auto &entry: autoApply)
|
||||
{
|
||||
std::string entryStr = OSUtils::jsonString(entry, "");
|
||||
|
||||
CT("AUTO APPLY SETTING: %s", entryStr.c_str());
|
||||
CamoClass camoClass = stringToClass(entryStr);
|
||||
if (camoClass < CamoClass::AUTO_APPLY_COUNT)
|
||||
{
|
||||
char c = ' ';
|
||||
if (i < temp.size())
|
||||
{
|
||||
c = temp[i];
|
||||
}
|
||||
camoWord |= c;
|
||||
camoWord <<= 8;
|
||||
camoAutoApply[camoClass] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
CT("CAMO WORD SETTING: %x", camoWord);
|
||||
|
||||
std::string relayRuleStr = OSUtils::jsonString(camo["relayRule"], "leave");
|
||||
std::transform(relayRuleStr.begin(), relayRuleStr.end(), relayRuleStr.begin(), [](unsigned char c)
|
||||
|
@ -1582,11 +1572,15 @@ public:
|
|||
if (knownHostsSection.is_object())
|
||||
{
|
||||
CT("KNOWN HOSTS SECTION FOUND");
|
||||
auto processLevelSection = [&knownHosts](const json §ion, CamoLevel level)
|
||||
|
||||
for (auto it = knownHostsSection.begin(); it != knownHostsSection.end(); it++)
|
||||
{
|
||||
if (section.is_array())
|
||||
std::string classKey = it.key();
|
||||
|
||||
CT("FOUND CAMO CLASS: %s", classKey.c_str());
|
||||
if (it.value().is_array())
|
||||
{
|
||||
for (const auto &addrStr: section)
|
||||
for (const auto &addrStr: it.value())
|
||||
{
|
||||
std::string addr = OSUtils::jsonString(addrStr, "");
|
||||
if (!addr.empty())
|
||||
|
@ -1595,46 +1589,11 @@ public:
|
|||
if (host)
|
||||
{
|
||||
CT("VALID HOST FOUND: %s", addr.c_str());
|
||||
knownHosts[host] = level;
|
||||
knownHosts[host] = stringToClass(classKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (auto it = knownHostsSection.begin(); it != knownHostsSection.end(); it++)
|
||||
{
|
||||
std::string levelKey = it.key();
|
||||
std::transform(levelKey.begin(), levelKey.end(), levelKey.begin(), [](unsigned char c)
|
||||
{
|
||||
return std::tolower(c);
|
||||
});
|
||||
|
||||
CT("FOUND CAMO LEVEL: %s", levelKey.c_str());
|
||||
if (levelKey == "none")
|
||||
{
|
||||
processLevelSection(it.value(), CamoLevel::NONE);
|
||||
}
|
||||
else if (levelKey == "node")
|
||||
{
|
||||
processLevelSection(it.value(), CamoLevel::NODE);
|
||||
}
|
||||
else if (levelKey == "controller")
|
||||
{
|
||||
processLevelSection(it.value(), CamoLevel::CONTROLLER);
|
||||
}
|
||||
else if (levelKey == "moon")
|
||||
{
|
||||
processLevelSection(it.value(), CamoLevel::MOON);
|
||||
}
|
||||
else if (levelKey == "planet")
|
||||
{
|
||||
processLevelSection(it.value(), CamoLevel::PLANET);
|
||||
}
|
||||
else
|
||||
{
|
||||
processLevelSection(it.value(), CamoLevel::INAPPLICABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1643,7 +1602,7 @@ public:
|
|||
CT("CAMO CONFIG SECTION NOT FOUND");
|
||||
}
|
||||
}
|
||||
CamoPattern::init(camoLevel, camoWord, knownHosts, relayRule);
|
||||
CamoPattern::init(camoAutoApply, knownHosts, relayRule);
|
||||
|
||||
// Set trusted paths if there are any
|
||||
if (!ppc.empty()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue