Removed licensing system related code
This commit is contained in:
parent
c2c94bb4b4
commit
82883d39ea
7 changed files with 2 additions and 276 deletions
|
@ -74,10 +74,9 @@ else()
|
||||||
message("Shared memory use is turned OFF")
|
message("Shared memory use is turned OFF")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT DEFINED FILLER_DATA OR NOT DEFINED SHARED_SECRET OR NOT DEFINED SUPER_SECRET)#LTS
|
if (FILLER_DATA AND SHARED_SECRET AND SUPER_SECRET)
|
||||||
message(WARNING "Not all LTS variables have been set and this is an LTS build - are you sure about this?")#LTS
|
|
||||||
endif()#LTS
|
|
||||||
add_definitions(-DFILLER_DATA="${FILLER_DATA}" -DSHARED_SECRET="${SHARED_SECRET}" -DSUPER_SECRET="${SUPER_SECRET}")#LTS
|
add_definitions(-DFILLER_DATA="${FILLER_DATA}" -DSHARED_SECRET="${SHARED_SECRET}" -DSUPER_SECRET="${SUPER_SECRET}")#LTS
|
||||||
|
endif()
|
||||||
|
|
||||||
option(GEOIP "Enable GeoIP capabilities (deprecated)")
|
option(GEOIP "Enable GeoIP capabilities (deprecated)")
|
||||||
if (GEOIP)
|
if (GEOIP)
|
||||||
|
@ -817,7 +816,6 @@ add_executable(MistController
|
||||||
src/controller/controller_capabilities.h
|
src/controller/controller_capabilities.h
|
||||||
src/controller/controller_streams.h
|
src/controller/controller_streams.h
|
||||||
src/controller/controller_push.h
|
src/controller/controller_push.h
|
||||||
src/controller/controller_license.h
|
|
||||||
src/controller/controller.cpp
|
src/controller/controller.cpp
|
||||||
src/controller/controller_updater.cpp
|
src/controller/controller_updater.cpp
|
||||||
src/controller/controller_streams.cpp
|
src/controller/controller_streams.cpp
|
||||||
|
@ -829,7 +827,6 @@ add_executable(MistController
|
||||||
src/controller/controller_uplink.cpp
|
src/controller/controller_uplink.cpp
|
||||||
src/controller/controller_api.cpp
|
src/controller/controller_api.cpp
|
||||||
src/controller/controller_push.cpp
|
src/controller/controller_push.cpp
|
||||||
src/controller/controller_license.cpp
|
|
||||||
generated/server.html.h
|
generated/server.html.h
|
||||||
${BINARY_DIR}/mist/.headers
|
${BINARY_DIR}/mist/.headers
|
||||||
)
|
)
|
||||||
|
|
|
@ -358,9 +358,6 @@ bool Util::Config::parseArgs(int &argc, char **&argv){
|
||||||
std::cout << "This makes them less accurate." << std::endl;
|
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
|
#endif
|
||||||
/*LTS-END*/
|
/*LTS-END*/
|
||||||
std::cout << "Built on " __DATE__ ", " __TIME__ << std::endl;
|
std::cout << "Built on " __DATE__ ", " __TIME__ << std::endl;
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
/*LTS-START*/
|
/*LTS-START*/
|
||||||
#include "controller_license.h"
|
|
||||||
#include "controller_limits.h"
|
#include "controller_limits.h"
|
||||||
#include "controller_updater.h"
|
#include "controller_updater.h"
|
||||||
#include "controller_uplink.h"
|
#include "controller_uplink.h"
|
||||||
|
@ -528,11 +527,6 @@ int main_loop(int argc, char **argv){
|
||||||
/*LTS-START*/
|
/*LTS-START*/
|
||||||
#ifdef UPDATER
|
#ifdef UPDATER
|
||||||
if (Controller::conf.getBool("update")){Controller::checkUpdates();}
|
if (Controller::conf.getBool("update")){Controller::checkUpdates();}
|
||||||
#endif
|
|
||||||
#ifdef LICENSING
|
|
||||||
Controller::initLicense();
|
|
||||||
// start license checking thread
|
|
||||||
tthread::thread licenseThread(Controller::licenseLoop, 0);
|
|
||||||
#endif
|
#endif
|
||||||
/*LTS-END*/
|
/*LTS-END*/
|
||||||
|
|
||||||
|
@ -548,9 +542,6 @@ int main_loop(int argc, char **argv){
|
||||||
}
|
}
|
||||||
if (Util::Config::is_restarting){shutdown_reason = "restart (on request)";}
|
if (Util::Config::is_restarting){shutdown_reason = "restart (on request)";}
|
||||||
/*LTS-START*/
|
/*LTS-START*/
|
||||||
#ifdef LICENSING
|
|
||||||
if (!Controller::isLicensed()){shutdown_reason = "no valid license";}
|
|
||||||
#endif
|
|
||||||
if (Triggers::shouldTrigger("SYSTEM_STOP")){
|
if (Triggers::shouldTrigger("SYSTEM_STOP")){
|
||||||
if (!Triggers::doTrigger("SYSTEM_STOP", shutdown_reason)){
|
if (!Triggers::doTrigger("SYSTEM_STOP", shutdown_reason)){
|
||||||
Controller::conf.is_active = true;
|
Controller::conf.is_active = true;
|
||||||
|
@ -580,10 +571,6 @@ int main_loop(int argc, char **argv){
|
||||||
uplinkThread.join();
|
uplinkThread.join();
|
||||||
HIGH_MSG("Joining push thread...");
|
HIGH_MSG("Joining push thread...");
|
||||||
pushThread.join();
|
pushThread.join();
|
||||||
#ifdef LICENSING
|
|
||||||
HIGH_MSG("Joining license thread...");
|
|
||||||
licenseThread.join();
|
|
||||||
#endif
|
|
||||||
#ifdef UPDATER
|
#ifdef UPDATER
|
||||||
HIGH_MSG("Joining updater thread...");
|
HIGH_MSG("Joining updater thread...");
|
||||||
updaterThread.join();
|
updaterThread.join();
|
||||||
|
@ -597,11 +584,6 @@ int main_loop(int argc, char **argv){
|
||||||
// give everything some time to print messages
|
// give everything some time to print messages
|
||||||
Util::wait(100);
|
Util::wait(100);
|
||||||
std::cout << "Killed all processes, wrote config to disk. Exiting." << std::endl;
|
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;}
|
if (Util::Config::is_restarting){return 42;}
|
||||||
// close stderr to make the stderr reading thread exit
|
// close stderr to make the stderr reading thread exit
|
||||||
close(STDERR_FILENO);
|
close(STDERR_FILENO);
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include <mist/url.h>
|
#include <mist/url.h>
|
||||||
#include <sys/stat.h> //for browse API call
|
#include <sys/stat.h> //for browse API call
|
||||||
/*LTS-START*/
|
/*LTS-START*/
|
||||||
#include "controller_license.h"
|
|
||||||
#include "controller_limits.h"
|
#include "controller_limits.h"
|
||||||
#include "controller_push.h"
|
#include "controller_push.h"
|
||||||
#include "controller_updater.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"] = Controller::Storage["config"];
|
||||||
Response["config"]["iid"] = instanceId;
|
Response["config"]["iid"] = instanceId;
|
||||||
Response["config"]["version"] = PACKAGE_VERSION " " RELEASE;
|
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
|
// add required data to the current unix time to the config, for syncing reasons
|
||||||
Response["config"]["time"] = Util::epoch();
|
Response["config"]["time"] = Util::epoch();
|
||||||
if (!Response["config"].isMember("serverid")){Response["config"]["serverid"] = "";}
|
if (!Response["config"].isMember("serverid")){Response["config"]["serverid"] = "";}
|
||||||
|
|
|
@ -1,211 +0,0 @@
|
||||||
#include "controller_license.h"
|
|
||||||
#include "controller_storage.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <mist/auth.h>
|
|
||||||
#include <mist/config.h>
|
|
||||||
#include <mist/defines.h>
|
|
||||||
#include <mist/downloader.h>
|
|
||||||
#include <mist/encode.h>
|
|
||||||
#include <mist/encryption.h>
|
|
||||||
#include <mist/http_parser.h>
|
|
||||||
#include <mist/socket.h>
|
|
||||||
#include <mist/timing.h>
|
|
||||||
|
|
||||||
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
|
|
|
@ -1,15 +0,0 @@
|
||||||
|
|
||||||
#include <mist/json.h>
|
|
||||||
|
|
||||||
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
|
|
|
@ -1043,24 +1043,6 @@ namespace Mist{
|
||||||
|
|
||||||
void OutHTTP::sendIcon(){
|
void OutHTTP::sendIcon(){
|
||||||
std::string method = H.method;
|
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();
|
H.Clean();
|
||||||
#include "../icon.h"
|
#include "../icon.h"
|
||||||
H.SetHeader("Content-Type", "image/x-icon");
|
H.SetHeader("Content-Type", "image/x-icon");
|
||||||
|
|
Loading…
Add table
Reference in a new issue