From 82883d39ea0ea56e5b4becbd17dd9e8b3be3b48f Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 9 Feb 2022 11:32:35 +0100 Subject: [PATCH] Removed licensing system related code --- CMakeLists.txt | 7 +- lib/config.cpp | 3 - src/controller/controller.cpp | 18 --- src/controller/controller_api.cpp | 6 - src/controller/controller_license.cpp | 211 -------------------------- src/controller/controller_license.h | 15 -- src/output/output_http_internal.cpp | 18 --- 7 files changed, 2 insertions(+), 276 deletions(-) delete mode 100644 src/controller/controller_license.cpp delete mode 100644 src/controller/controller_license.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 17698c56..754ed9e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,10 +74,9 @@ else() message("Shared memory use is turned OFF") endif() -if (NOT DEFINED FILLER_DATA OR NOT DEFINED SHARED_SECRET OR NOT DEFINED SUPER_SECRET)#LTS - message(WARNING "Not all LTS variables have been set and this is an LTS build - are you sure about this?")#LTS -endif()#LTS +if (FILLER_DATA AND SHARED_SECRET AND SUPER_SECRET) add_definitions(-DFILLER_DATA="${FILLER_DATA}" -DSHARED_SECRET="${SHARED_SECRET}" -DSUPER_SECRET="${SUPER_SECRET}")#LTS +endif() option(GEOIP "Enable GeoIP capabilities (deprecated)") if (GEOIP) @@ -817,7 +816,6 @@ add_executable(MistController src/controller/controller_capabilities.h src/controller/controller_streams.h src/controller/controller_push.h - src/controller/controller_license.h src/controller/controller.cpp src/controller/controller_updater.cpp src/controller/controller_streams.cpp @@ -829,7 +827,6 @@ add_executable(MistController src/controller/controller_uplink.cpp src/controller/controller_api.cpp src/controller/controller_push.cpp - src/controller/controller_license.cpp generated/server.html.h ${BINARY_DIR}/mist/.headers ) diff --git a/lib/config.cpp b/lib/config.cpp index 9a5d9e65..5e9ce11a 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -358,9 +358,6 @@ bool Util::Config::parseArgs(int &argc, char **&argv){ std::cout << "This makes them less accurate." << std::endl; } } -#endif -#ifndef LICENSING - std::cout << "- Flag: Licensing system disabled. No checks for validity will occur." << std::endl; #endif /*LTS-END*/ std::cout << "Built on " __DATE__ ", " __TIME__ << std::endl; diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 3a6fcd74..2c01c0cd 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -28,7 +28,6 @@ #include #include /*LTS-START*/ -#include "controller_license.h" #include "controller_limits.h" #include "controller_updater.h" #include "controller_uplink.h" @@ -528,11 +527,6 @@ int main_loop(int argc, char **argv){ /*LTS-START*/ #ifdef UPDATER if (Controller::conf.getBool("update")){Controller::checkUpdates();} -#endif -#ifdef LICENSING - Controller::initLicense(); - // start license checking thread - tthread::thread licenseThread(Controller::licenseLoop, 0); #endif /*LTS-END*/ @@ -548,9 +542,6 @@ int main_loop(int argc, char **argv){ } if (Util::Config::is_restarting){shutdown_reason = "restart (on request)";} /*LTS-START*/ -#ifdef LICENSING - if (!Controller::isLicensed()){shutdown_reason = "no valid license";} -#endif if (Triggers::shouldTrigger("SYSTEM_STOP")){ if (!Triggers::doTrigger("SYSTEM_STOP", shutdown_reason)){ Controller::conf.is_active = true; @@ -580,10 +571,6 @@ int main_loop(int argc, char **argv){ uplinkThread.join(); HIGH_MSG("Joining push thread..."); pushThread.join(); -#ifdef LICENSING - HIGH_MSG("Joining license thread..."); - licenseThread.join(); -#endif #ifdef UPDATER HIGH_MSG("Joining updater thread..."); updaterThread.join(); @@ -597,11 +584,6 @@ int main_loop(int argc, char **argv){ // give everything some time to print messages Util::wait(100); std::cout << "Killed all processes, wrote config to disk. Exiting." << std::endl; - if (Controller::exitDelay){ - std::cout << "Delaying shutdown by " << Controller::exitDelay - << " seconds, on license server request..." << std::endl; - while (Controller::exitDelay--){Util::wait(1000);} - } if (Util::Config::is_restarting){return 42;} // close stderr to make the stderr reading thread exit close(STDERR_FILENO); diff --git a/src/controller/controller_api.cpp b/src/controller/controller_api.cpp index f7e15622..4d94bb11 100644 --- a/src/controller/controller_api.cpp +++ b/src/controller/controller_api.cpp @@ -17,7 +17,6 @@ #include #include //for browse API call /*LTS-START*/ -#include "controller_license.h" #include "controller_limits.h" #include "controller_push.h" #include "controller_updater.h" @@ -976,11 +975,6 @@ void Controller::handleAPICommands(JSON::Value &Request, JSON::Value &Response){ Response["config"] = Controller::Storage["config"]; Response["config"]["iid"] = instanceId; Response["config"]["version"] = PACKAGE_VERSION " " RELEASE; -/*LTS-START*/ -#ifdef LICENSING - Response["config"]["license"] = getLicense(); -#endif - /*LTS-END*/ // add required data to the current unix time to the config, for syncing reasons Response["config"]["time"] = Util::epoch(); if (!Response["config"].isMember("serverid")){Response["config"]["serverid"] = "";} diff --git a/src/controller/controller_license.cpp b/src/controller/controller_license.cpp deleted file mode 100644 index a5a535b6..00000000 --- a/src/controller/controller_license.cpp +++ /dev/null @@ -1,211 +0,0 @@ -#include "controller_license.h" -#include "controller_storage.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Controller{ - - uint64_t exitDelay = 0; - static JSON::Value currentLicense; - static uint64_t lastCheck = 0; - static int32_t timeOffset = 0; - static bool everContactedServer = false; - - const JSON::Value &getLicense(){return currentLicense;} - - // PACKAGE_VERSION = MistServer version - // RELEASE = OS + user_ID - - void initLicense(){ - if (Storage.isMember("license") && Storage.isMember("license_id")){ - INFO_MSG("Reading license from storage") - readLicense(Storage["license_id"].asInt(), Storage["license"].asStringRef()); - if (!isLicensed()){ - updateLicense("&boot=1"); - checkLicense(); - }else{ - lastCheck = std::min(Util::epoch(), (uint64_t)currentLicense["valid_from"].asInt()); - } - }else{ - updateLicense("&boot=1"); - checkLicense(); - } - } - - bool isLicensed(){ - uint64_t now = Util::epoch() + timeOffset; -#if DEBUG >= DLVL_DEVEL - INFO_MSG("Verifying license against %" PRIu64 ": %s", now, currentLicense.toString().c_str()); -#endif - // Print messages for user, if any - if (currentLicense.isMember("user_msg") && currentLicense["user_msg"].asStringRef().size()){ - WARN_MSG("%s", currentLicense["user_msg"].asStringRef().c_str()); - } - // Check time - if (!currentLicense.isMember("valid_from") || !currentLicense.isMember("valid_till") || - now < currentLicense["valid_from"].asInt() || now > currentLicense["valid_till"].asInt()){ - return false; // license is expired - } - // Check release/version - if (RELEASE != currentLicense["release"].asStringRef() || - PACKAGE_VERSION != currentLicense["version"].asStringRef()){ - FAIL_MSG("Could not verify license"); - return false; - } - // everything seems okay - return true; - } - - bool checkLicense(){ - if (!conf.is_active){return true;} - INFO_MSG("Checking license validity"); - if (!everContactedServer && !isLicensed()){updateLicense("&expired=1");} - if (!isLicensed()){ - FAIL_MSG("Not licensed, shutting down"); - if (currentLicense.isMember("delay") && currentLicense["delay"].asInt()){ - exitDelay = currentLicense["delay"].asInt(); - } - kill(getpid(), SIGINT); - conf.is_active = false; - return false; - } - lastCheck = Util::epoch(); - return true; - } - - void parseKey(std::string key, char *newKey, unsigned int len){ - memset(newKey, 0, len); - for (size_t i = 0; i < key.size() && i < (len << 1); ++i){ - char c = key[i]; - newKey[i >> 1] |= ((c & 15) + (((c & 64) >> 6) | ((c & 64) >> 3))) << ((~i & 1) << 2); - } - } - - void updateLicense(const std::string &extra){ - INFO_MSG("Running license updater %s", extra.c_str()); - JSON::Value response; - - HTTP::Downloader dl; - dl.dataTimeout = 25; // 25-second data timeout, increased from 5s default -#ifdef SSL - HTTP::URL url("https://releases.mistserver.org/license.php"); - if (dl.isProxied()){url.protocol = "http";} -#else - HTTP::URL url("http://releases.mistserver.org/license.php"); -#endif - url.args = "release=" + Encodings::URL::encode(RELEASE) + - "&version=" + Encodings::URL::encode(PACKAGE_VERSION) + - "&iid=" + Encodings::URL::encode(instanceId) + - "&hrn=" + Encodings::URL::encode(Storage["config"]["serverid"]) + - "&lid=" + currentLicense["lic_id"].asString() + extra; - - long long currID = currentLicense["lic_id"].asInt(); - if (currID){ - char aesKey[16]; - if (strlen(SUPER_SECRET) >= 32){ - parseKey((SUPER_SECRET SUPER_SECRET) + 7, aesKey, 16); - }else{ - parseKey("4E56721C67306E1F473156F755FF5570", aesKey, 16); - } - for (unsigned int i = 0; i < 8; ++i){ - aesKey[15 - i] = ((currID >> (i * 8)) + aesKey[15 - i]) & 0xFF; - } - - Encryption::AES crypter; - crypter.setEncryptKey(aesKey); - // 0 here for 0-filled ivec. - dl.setHeader("X-IRDGAF", - Encodings::Base64::encode(crypter.encryptBlockCTR(0, RELEASE "|" PACKAGE_VERSION))); - } - if (!dl.get(url) || !dl.isOk()){return;} - response = JSON::fromString(dl.data()); - everContactedServer = true; - - // read license - readLicense(response["lic_id"].asInt(), response["license"].asStringRef(), true); - } - - void readLicense(uint64_t licID, const std::string &input, bool fromServer){ - char aesKey[16]; - if (strlen(SUPER_SECRET) >= 32){ - parseKey((SUPER_SECRET SUPER_SECRET) + 7, aesKey, 16); - }else{ - parseKey("4E56721C67306E1F473156F755FF5570", aesKey, 16); - } - for (unsigned int i = 0; i < 8; ++i){ - aesKey[15 - i] = ((licID >> (i * 8)) + aesKey[15 - i]) & 0xFF; - } - std::string cipher = Encodings::Base64::decode(input); - // magic ivecs, they are empty. It's secretly 16 times \0. - Encryption::AES crypter; - crypter.setEncryptKey(aesKey); - // 0 here for 0-filled ivec. - std::string deCrypted = crypter.encryptBlockCTR(0, cipher); - - // get time stamps and license. - - // verify checksum - if (deCrypted.size() < 33 || Secure::md5(deCrypted.substr(32)) != deCrypted.substr(0, 32)){ - WARN_MSG("Could not decode license"); - return; - } - JSON::Value newLicense = JSON::fromString(deCrypted.substr(32)); - if (RELEASE != newLicense["release"].asStringRef() || - PACKAGE_VERSION != newLicense["version"].asStringRef()){ - FAIL_MSG("Could not verify license"); - return; - } - - if (fromServer){ - uint64_t localTime = Util::epoch(); - uint64_t remoteTime = newLicense["time"].asInt(); - if (localTime > remoteTime + 60){ - WARN_MSG("Your computer clock is %" PRIu64 - " seconds ahead! Please ensure your computer clock is set correctly.", - localTime - remoteTime); - } - if (localTime < remoteTime - 60){ - WARN_MSG("Your computer clock is %" PRIu64 - " seconds late! Please ensure your computer clock is set correctly.", - remoteTime - localTime); - } - timeOffset = remoteTime - localTime; - - if (newLicense.isMember("plid") && newLicense["plid"] != currentLicense["lic_id"]){ - FAIL_MSG("Could not verify license ID"); - return; - } - } - - currentLicense = newLicense; - - // Store license here. - if (currentLicense["store"].asBool()){ - if (Storage["license"].asStringRef() != input){ - Storage["license"] = input; - Storage["license_id"] = licID; - INFO_MSG("Stored license for offline use"); - } - } - } - - void licenseLoop(void *np){ - while (conf.is_active){ - uint64_t interval = currentLicense["interval"].asInt(); - if (Util::epoch() - lastCheck > (interval ? interval : 3600)){ - if (interval){updateLicense();} - checkLicense(); - } - Util::sleep(1000); // sleep a bit - } - if (everContactedServer){updateLicense("&shutdown=1");} - } -}// namespace Controller diff --git a/src/controller/controller_license.h b/src/controller/controller_license.h deleted file mode 100644 index 34894958..00000000 --- a/src/controller/controller_license.h +++ /dev/null @@ -1,15 +0,0 @@ - -#include - -namespace Controller{ - extern uint64_t exitDelay; - - const JSON::Value &getLicense(); - void initLicense(); - bool isLicensed(); // checks/verifies license time - bool checkLicense(); // Call from Mainloop. - void updateLicense(const std::string &extra = ""); // retrieves update from license server - void licenseLoop(void *np); - void readLicense(uint64_t licId, const std::string &input, bool fromServer = false); // checks/interprets license - -}// namespace Controller diff --git a/src/output/output_http_internal.cpp b/src/output/output_http_internal.cpp index 1062ddd1..7b044fde 100644 --- a/src/output/output_http_internal.cpp +++ b/src/output/output_http_internal.cpp @@ -1043,24 +1043,6 @@ namespace Mist{ void OutHTTP::sendIcon(){ std::string method = H.method; - /*LTS-START*/ - if (H.GetVar("s").size() && H.GetVar("s") == SUPER_SECRET){ - H.Clean(); - H.SetHeader("Server", APPIDENT); - H.setCORSHeaders(); - if (method == "OPTIONS" || method == "HEAD"){ - H.SendResponse("200", "OK", myConn); - responded = true; - H.Clean(); - return; - } - H.SetBody("Yup"); - H.SendResponse("200", "OK", myConn); - responded = true; - H.Clean(); - return; - } - /*LTS-END*/ H.Clean(); #include "../icon.h" H.SetHeader("Content-Type", "image/x-icon");