Fixed some compile errors

This commit is contained in:
WolverinDEV 2020-03-02 13:33:57 +01:00
parent d3ee202313
commit 504c842499
29 changed files with 64 additions and 700 deletions

View File

@ -14,100 +14,65 @@ include_directories(../shared/src)
add_definitions(-DLTM_DESC)
set(LICENCE_SOURCE_FILES
shared/LicenseRequest.cpp
shared/LicenseRequestHandler.cpp
shared/License.cpp
shared/LicenseServerClient.cpp
../shared/src/log/LogUtils.cpp
shared/src/license.cpp
shared/src/client.cpp
)
#Protobuf
find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS packets/LicenseRequest.proto packets/LicenseManager.proto)
protobuf_generate_cpp(PROTO_SRCS TeaLicenseHelper_PROTOCOL_HEADERS shared/packets/LicenseRequest.proto shared/packets/LicenseManager.proto)
#The actual librarie
add_library(TeaLicenseHelper STATIC ${LICENCE_SOURCE_FILES} ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(TeaLicenseHelper PUBLIC TeaSpeak libevent::core libevent::pthreads)
#The actual shared library
add_library(TeaLicenseHelper STATIC ${LICENCE_SOURCE_FILES} ${PROTO_SRCS})
target_link_libraries(TeaLicenseHelper PUBLIC
TeaSpeak
protobuf::libprotobuf
libevent::core libevent::pthreads
openssl::ssl::shared
openssl::crypto::shared
${StringVariable_LIBRARIES_STATIC}
${ed25519_LIBRARIES_STATIC}
stdc++fs
)
target_include_directories(TeaLicenseHelper PUBLIC shared/include/)
target_include_directories(TeaLicenseHelper PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
#The license server
add_executable(TeaLicenseServer ${LICENCE_SOURCE_FILES} ${PROTO_SRCS} ${PROTO_HDRS}
add_executable(TeaLicenseServer ${LICENCE_SOURCE_FILES}
server/KeyIdCache.cpp
server/LicenseServer.cpp
server/LicenseServerHandler.cpp
server/DatabaseHandler.cpp
LicenseServerMain.cpp
server/WebAPI.cpp
server/StatisticManager.cpp
server/UserManager.cpp
LicenseServerMain.cpp
MySQLLibSSLFix.c
)
target_compile_options(TeaLicenseServer PRIVATE "-Wl,--unresolved-symbols=ignore-in-object-files")
target_link_libraries(TeaLicenseServer
TeaSpeak
TeaLicenseHelper #Static
threadpool::static #Static
TeaSpeak #Static
TeaLicenseHelper #Static
CXXTerminal::static #Static
${StringVariable_LIBRARIES_STATIC}
# stdc++fs
libevent::core libevent::pthreads
yaml-cpp
${LIBRARY_PATH_PROTOBUF}
${ed25519_LIBRARIES_STATIC}
#We're forsed to use boringssl caused by the fact that boringssl is already within webrtc!
#Require a so
sqlite3
protobuf::libprotobuf
tomcrypt::static
tommath::static
mysqlclient.a
mysqlclient
jsoncpp_lib
${DataPipes_LIBRARIES_SHARED} # Also includes glib2.0
DataPipes::core::shared
openssl::ssl::shared
openssl::crypto::shared
pthread
dl
z
)
if (COMPILE_WEB_CLIENT)
target_link_libraries(TeaLicenseServer ${glib20_DIR}/lib/x86_64-linux-gnu/libffi.so.7 ${nice_DIR}/lib/libnice.so.10)
endif ()
include_directories(${LIBRARY_PATH}/boringssl/include/)
#The test license client
add_executable(TeaLicenseClient
LicenseClientMain.cpp
${LICENCE_SOURCE_FILES} ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(TeaLicenseClient
TeaSpeak #Static
protobuf::libprotobuf
stdc++fs
libevent::core libevent::pthreads
${ed25519_LIBRARIES_STATIC}
${StringVariable_LIBRARIES_STATIC}
CXXTerminal::static #Static
tomcrypt::static
tommath::static
${DataPipes_LIBRARIES_SHARED} # Also includes glib2.0
${glib20_DIR}/lib/x86_64-linux-gnu/libffi.so.7 ${nice_DIR}/lib/libnice.so.10
openssl::ssl::shared
openssl::crypto::shared
pthread
dl
z
)
add_executable(TeaLicenseClient LicenseClientMain.cpp)
target_link_libraries(TeaLicenseClient TeaLicenseHelper)
#The license manager
if(NOT DISABLE_QT)
@ -162,17 +127,6 @@ add_executable(LicenseCLI
manager/ServerConnection.cpp
manager/ServerConnectionExecutor.cpp
manager/ServerConnectionHandler.cpp
shared/License.cpp
${PROTO_SRCS} ${PROTO_HDRS}
)
target_link_libraries(LicenseCLI
TeaSpeak
libevent::core libevent::pthreads
threadpool::static #Static
tomcrypt::static
tommath::static
protobuf::libprotobuf
${ed25519_LIBRARIES_STATIC}
pthread
)
target_link_libraries(LicenseCLI TeaLicenseHelper)

View File

@ -1,8 +1,8 @@
#include <iostream>
#include <shared/License.h>
#include <shared/LicenseRequest.h>
#include <shared/include/license/license.h>
#include <shared/include/license/LicenseRequest.h>
#include <event2/thread.h>
#include "shared/LicenseServerClient.h"
#include "shared/include/license/client.h"
#include <random>
#include <ed25519/ed25519.h>

View File

@ -1,6 +1,6 @@
#include <iostream>
#include <shared/License.h>
#include <shared/LicenseRequest.h>
#include <shared/include/license/license.h>
#include <shared/include/license/LicenseRequest.h>
#include <QtWidgets/QApplication>
#include <manager/ui/LicenseGenerator.h>
#include <manager/ServerConnection.h>

View File

@ -3,8 +3,8 @@
//
#include <netinet/tcp.h>
#include <shared/crypt.h>
#include <shared/License.h>
#include <shared/src/crypt.h>
#include <shared/include/license/license.h>
#include <memory>
#include <misc/std_unique_ptr.h>
#include <ThreadPool/ThreadHelper.h>

View File

@ -6,7 +6,7 @@
#include <deque>
#include <thread>
#include <ThreadPool/Thread.h>
#include "shared/License.h"
#include "shared/include/license/license.h"
#define FLSUCCESS(listener, object) \
do { \

View File

@ -2,8 +2,8 @@
#include <misc/endianness.h>
#include <LicenseRequest.pb.h>
#include <LicenseManager.pb.h>
#include <shared/crypt.h>
#include <shared/License.h>
#include <shared/src/crypt.h>
#include <shared/include/license/license.h>
#include <misc/std_unique_ptr.h>
#include "ServerConnection.h"

View File

@ -1,7 +1,7 @@
#pragma once
#include <sql/SqlQuery.h>
#include <shared/License.h>
#include <shared/include/license/license.h>
#include <LicenseRequest.pb.h>
namespace license::server::database {

View File

@ -8,8 +8,8 @@
#include <log/LogUtils.h>
#include <misc/endianness.h>
#include <LicenseRequest.pb.h>
#include <shared/License.h>
#include <shared/crypt.h>
#include <shared/include/license/license.h>
#include <shared/src/crypt.h>
#include <ThreadPool/ThreadHelper.h>
#include "LicenseServer.h"
#include "UserManager.h"
@ -363,10 +363,11 @@ void LicenseServer::handleMessage(shared_ptr<ConnectedClient>& client, const std
memcpy(&packet.header, message.data(), sizeof(protocol::packet::header));
packet.data = message.substr(sizeof(protocol::packet::header), packet.header.length);
if(!client->protocol.cryptKey.empty())
if(!client->protocol.cryptKey.empty()) {
xorBuffer((char*) packet.data.data(), packet.data.length(), client->protocol.cryptKey.data(), client->protocol.cryptKey.length());
}
bool success = false;
bool success{false};
string error;
try {
if(packet.header.packetId == protocol::PACKET_CLIENT_HANDSHAKE) {

View File

@ -9,7 +9,7 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <ThreadPool/Thread.h>
#include <shared/License.h>
#include <shared/include/license/license.h>
#include <arpa/inet.h>
#include "DatabaseHandler.h"

View File

@ -3,9 +3,9 @@
#include <misc/hex.h>
#include <log/LogUtils.h>
#include <LicenseManager.pb.h>
#include <shared/License.h>
#include <shared/include/license/license.h>
#include "LicenseRequest.pb.h"
#include "shared/License.h"
#include "shared/include/license/license.h"
#include "LicenseServer.h"
#include "WebAPI.h"
#include "StatisticManager.h"

View File

@ -9,7 +9,7 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <ThreadPool/Thread.h>
#include <shared/License.h>
#include <shared/include/license/license.h>
#include <arpa/inet.h>
#include <misc/net.h>
#include <json/json.h>

View File

@ -1,306 +0,0 @@
#include <netinet/tcp.h>
#include <fcntl.h>
#include <log/LogUtils.h>
#include <misc/memtracker.h>
#include "crypt.h"
#define DEFINE_HELPER
#include "LicenseRequest.h"
#include "License.h"
#include <csignal>
#include <ThreadPool/ThreadHelper.h>
#include <unistd.h>
using namespace std;
using namespace std::chrono;
using namespace ts;
using namespace license;
//#define DEBUG_LICENSE_CLIENT
#define CERR(message) LICENSE_FERR(this, CouldNotConnectException, message)
LicenceRequest::LicenceRequest(const std::shared_ptr<LicenseRequestData> & license, const sockaddr_in& remoteAddr) : data{license} {
#ifdef DEBUG_LICENSE_CLIENT
memtrack::allocated<LicenceRequest>(this);
#endif
memcpy(&this->remote_address, &remoteAddr, sizeof(remoteAddr));
assert(license->info);
}
LicenceRequest::~LicenceRequest() {
#ifdef DEBUG_LICENSE_CLIENT
memtrack::freed<LicenceRequest>(this);
#endif
this->abortRequest();
threads::save_join(this->closeThread);
delete this->currentFuture;
this->currentFuture = nullptr;
}
threads::Future<std::shared_ptr<LicenseRequestResponse>> LicenceRequest::requestInfo() {
{
lock_guard lock(this->lock);
if(this->currentFuture) return *this->currentFuture;
this->currentFuture = new threads::Future<std::shared_ptr<LicenseRequestResponse>>();
}
this->beginRequest();
return *this->currentFuture;
}
//Basic IO
void LicenceRequest::handleEventWrite(int fd, short event, void* ptrClient) {
auto* client = static_cast<LicenceRequest *>(ptrClient);
buffer::RawBuffer* buffer = nullptr;
{
lock_guard lock(client->lock);
if((event & EV_TIMEOUT) > 0) { //Connect timeout
LICENSE_FERR(client, ConnectionException, "Connect timeout");
return;
}
if(client->state == protocol::CONNECTING){
client->handleConnected();
}
if(client->state == protocol::UNCONNECTED || !client->event_write)
return;
buffer = TAILQ_FIRST(&client->writeQueue);
if(!buffer) return;
auto writtenBytes = send(fd, &buffer->buffer[buffer->index], buffer->length - buffer->index, MSG_NOSIGNAL | MSG_DONTWAIT);
buffer->index += writtenBytes;
if(buffer->index >= buffer->length) {
TAILQ_REMOVE(&client->writeQueue, buffer, tail);
delete buffer;
}
if(!TAILQ_EMPTY(&client->writeQueue))
event_add(client->event_write, nullptr);
}
}
void LicenceRequest::sendPacket(const protocol::packet& packet) {
if(this->state == protocol::UNCONNECTED || this->state == protocol::DISCONNECTING) {
if(this->verbose)
logError(LOG_GENERAL, "Tried to send a packet to an unconnected remote!");
return;
}
packet.prepare();
auto buffer = new buffer::RawBuffer(packet.data.length() + sizeof(packet.header));
memcpy(buffer->buffer, &packet.header, sizeof(packet.header));
memcpy(&buffer->buffer[sizeof(packet.header)], packet.data.data(), packet.data.length());
if(!this->cryptKey.empty())
xorBuffer(&buffer->buffer[sizeof(packet.header)], packet.data.length(), this->cryptKey.data(), this->cryptKey.length());
{
lock_guard lock(this->lock);
TAILQ_INSERT_TAIL(&this->writeQueue, buffer, tail);
if(this->event_write)
event_add(this->event_write, nullptr);
}
}
void LicenceRequest::handleEventRead(int fd, short, void* ptrClient) {
auto* client = static_cast<LicenceRequest *>(ptrClient);
auto buffer = std::unique_ptr<void, decltype(free)*>{malloc(1024), free};
sockaddr_in remoteAddr{};
socklen_t remoteAddrSize = sizeof(remoteAddr);
auto read = recvfrom(fd, buffer.get(), 1024, MSG_NOSIGNAL | MSG_DONTWAIT, reinterpret_cast<sockaddr *>(&remoteAddr), &remoteAddrSize);
if(read < 0){
if(errno == EWOULDBLOCK) return;
if(client->event_read)
event_del_noblock(client->event_read);
LICENSE_FERR(client, ConnectionException, "Invalid read: " + string(strerror(errno)) + "/" + to_string(errno));
return;
} else if(read == 0) {
if(client->event_read)
event_del_noblock(client->event_read);
LICENSE_FERR(client, ConnectionException, "IO error (" + to_string(errno) + "): " + string(strerror(errno)));
return;
}
client->handleMessage(string((char*) buffer.get(), read));
}
static int enabled = 1;
static int disabled = 0;
void LicenceRequest::beginRequest() {
lock_guard lock(this->lock);
TAILQ_INIT(&this->writeQueue);
this->file_descriptor = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
if(this->file_descriptor < 0) CERR("Socket setup failed");
signal(SIGPIPE, SIG_IGN);
auto connect_state = ::connect(this->file_descriptor, reinterpret_cast<const sockaddr *>(&this->remote_address), sizeof(this->remote_address));
if(connect_state < 0 && errno != EINPROGRESS) CERR("connect() failed (" + string(strerror(errno)) + ")");
if(setsockopt(this->file_descriptor, SOL_SOCKET, SO_REUSEADDR, &enabled, sizeof(enabled)) < 0); //CERR("could not set reuse addr");
if(setsockopt(this->file_descriptor, IPPROTO_TCP, TCP_CORK, &disabled, sizeof(disabled)) < 0); // CERR("could not set no push");
if(fcntl(this->file_descriptor, F_SETFD, fcntl(this->file_descriptor, F_GETFL, 0) | FD_CLOEXEC | O_NONBLOCK) < 0); // CERR("Failed to set FD_CLOEXEC and O_NONBLOCK (" + std::to_string(errno) + ")");
this->event_base = event_base_new();
this->event_read = event_new(this->event_base, this->file_descriptor, EV_READ | EV_PERSIST, LicenceRequest::handleEventRead, this);
this->event_write = event_new(this->event_base, this->file_descriptor, EV_WRITE, LicenceRequest::handleEventWrite, this);
this->state = protocol::CONNECTING; //First set connected, then we could enable the event loop
event_dispatch = std::thread([&]() {
signal(SIGPIPE, SIG_IGN);
{ /* now we could start listening */
lock_guard _lock(this->lock);
if(!this->event_read || !this->event_write) return;
event_add(this->event_read, nullptr);
timeval connect_timeout{5, 0};
event_add(this->event_write, &connect_timeout);
}
event_base_dispatch(this->event_base);
});
}
void LicenceRequest::handleConnected() {
this->state = protocol::HANDSCHAKE;
uint8_t handshakeBuffer[4];
handshakeBuffer[0] = 0xC0;
handshakeBuffer[1] = 0xFF;
handshakeBuffer[2] = 0xEE;
handshakeBuffer[3] = LICENSE_PROT_VERSION;
this->sendPacket(protocol::packet{protocol::PACKET_CLIENT_HANDSHAKE, string((const char*) handshakeBuffer, 4)}); //Initialise packet
}
void LicenceRequest::handleMessage(const std::string& message) {
this->buffer += message;
if(this->buffer.length() < sizeof(protocol::packet::header))
return;
protocol::packet packet{protocol::PACKET_DISCONNECT, ""};
memcpy(&packet.header, this->buffer.data(), sizeof(protocol::packet::header));
if(packet.header.length <= this->buffer.length() - sizeof(protocol::packet::header)) {
packet.data = this->buffer.substr(sizeof(protocol::packet::header), packet.header.length);
this->buffer = this->buffer.substr(sizeof(protocol::packet::header) + packet.header.length);
} else {
return;
}
if(!this->cryptKey.empty()) {
xorBuffer((char*) packet.data.data(), packet.data.length(), this->cryptKey.data(), this->cryptKey.length());
}
if(packet.header.packetId == protocol::PACKET_SERVER_HANDSHAKE) {
this->handlePacketHandshake(packet.data);
} else if(packet.header.packetId == protocol::PACKET_DISCONNECT) {
this->handlePacketDisconnect(packet.data);
} else if(packet.header.packetId == protocol::PACKET_SERVER_VALIDATION_RESPONSE) {
this->handlePacketLicenseInfo(packet.data);
} else if(packet.header.packetId == protocol::PACKET_SERVER_PROPERTY_ADJUSTMENT) {
this->handlePacketInfoAdjustment(packet.data);
} else
LICENSE_FERR(this, ConnectionException, "Invalid packet id (" + to_string(packet.header.packetId) + ")");
if(!this->buffer.empty() && this->state != protocol::DISCONNECTING && this->state != protocol::UNCONNECTED)
this->handleMessage("");
}
void LicenceRequest::disconnect(const std::string& message) {
if(this->state != protocol::UNCONNECTED && this->state != protocol::DISCONNECTING)
this->sendPacket({protocol::PACKET_DISCONNECT, message});
this->closeConnection();
//TODO flush?
}
void LicenceRequest::closeConnection() {
event *event_read{nullptr}, *event_write{nullptr};
{
lock_guard slock(this->lock);
if(this->state == protocol::UNCONNECTED) return;
if(this->event_dispatch.get_id() == this_thread::get_id()) { //We could not close in the same thread as we read/write (we're joining it later)
if(this->state == protocol::DISCONNECTING) return;
this->state = protocol::DISCONNECTING;
this->closeThread = std::thread(&LicenceRequest::closeConnection, this);
#ifdef DEBUG_LICENSE_CLIENT
if(this->verbose) {
debugMessage(LOG_GENERAL,"Running close in a new thread");
this->closeThread->name("License request close");
}
#endif
return;
}
this->state = protocol::UNCONNECTED;
std::swap(this->event_read, event_read);
std::swap(this->event_write, event_write);
}
if(event_read) {
event_del_block(event_read);
event_free(event_read);
}
if(event_write) {
event_del_block(event_write);
event_free(event_write);
}
/* close before base shutdown (else epoll hangup) */
if(this->file_descriptor > 0) {
shutdown(this->file_descriptor, SHUT_RDWR);
::close(this->file_descriptor);
}
this->file_descriptor = 0;
{
lock_guard lock(this->lock);
ts::buffer::RawBuffer* buffer;
while ((buffer = TAILQ_FIRST(&this->writeQueue))) {
TAILQ_REMOVE(&this->writeQueue, buffer, tail);
delete buffer;
}
}
{
if(this->event_base) {
timeval seconds{1, 0};
event_base_loopexit(this->event_base, &seconds);
event_base_loopexit(this->event_base, nullptr);
}
if(this->event_dispatch.joinable()) {
this->event_dispatch.join();
}
if(this->event_base) {
event_base_free(this->event_base);
this->event_base = nullptr;
}
}
#ifdef DEBUG_LICENSE_CLIENT
if(this->verbose)
debugMessage("Executing close done");
#endif
}
void LicenceRequest::abortRequest(const std::chrono::system_clock::time_point &timeout) {
this->closeConnection();
}

View File

@ -1,140 +0,0 @@
#pragma once
#include <thread>
#include <protocol/buffers.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <event.h>
#include "License.h"
#ifdef DEFINE_HELPER
#define LICENSE_FERR(this, class, message) \
do { \
this->currentException = std::make_shared<exceptions::class>(message); \
if(this->currentFuture && this->currentFuture->state() == threads::FutureState::WORKING) this->currentFuture->executionFailed(); \
this->disconnect("internal error"); \
return; \
} while(0)
#endif
namespace license {
namespace exceptions {
class CouldNotConnectException : public LicenseException {
public:
explicit CouldNotConnectException(const std::string &message) : LicenseException(message) {}
};
class ConnectionException : public LicenseException {
public:
explicit ConnectionException(const std::string &message) : LicenseException(message) {}
};
class UnexcpectedDisconnectException : public LicenseException {
public:
explicit UnexcpectedDisconnectException(const std::string &message) : LicenseException(message) {}
};
class InvalidResponseException : public LicenseException {
public:
explicit InvalidResponseException(const std::string &message) : LicenseException(message) {}
};
}
struct ServerInfo {
std::string unique_identifier;
int64_t timestamp;
std::string uname;
std::string version;
};
struct LicenseRequestResponse {
std::shared_ptr<LicenseInfo> license;
bool license_valid;
int64_t speach_varianz_adjustment;
bool speach_reset;
bool properties_valid;
std::chrono::system_clock::time_point age;
};
struct LicenseRequestData {
std::shared_ptr<License> license{nullptr};
std::shared_ptr<ServerInfo> info{nullptr};
std::string web_certificate_revision{};
int64_t speach_total = 0;
int64_t speach_dead = 0;
int64_t speach_online = 0;
int64_t speach_varianz = 0;
int64_t client_online = 0;
int64_t web_clients_online = 0;
int64_t bots_online = 0;
int64_t queries_online = 0;
int64_t servers_online = 0;
};
struct WebCertificate {
std::string revision;
std::string key;
std::string certificate;
};
class LicenceRequest {
public:
typedef threads::Future<std::shared_ptr<LicenseRequestResponse>> ResponseFuture;
LicenceRequest(const std::shared_ptr<LicenseRequestData>&, const sockaddr_in&);
~LicenceRequest();
std::shared_ptr<exceptions::LicenseException> exception(){ return this->currentException; }
void clearExceptions(){ this->currentException = nullptr; }
ResponseFuture requestInfo();
void abortRequest(const std::chrono::system_clock::time_point& timeout = std::chrono::system_clock::time_point());
void sendPacket(const protocol::packet&);
std::function<void(const WebCertificate& /* certificate */)> callback_update_certificate{nullptr};
std::function<void(const std::string& /* new key */)> callback_update_license{nullptr};
bool verbose = true;
private:
std::shared_ptr<LicenseRequestData> data;
threads::Future<std::shared_ptr<LicenseRequestResponse>>* currentFuture = nullptr;
std::shared_ptr<LicenseRequestResponse> response = nullptr;
std::shared_ptr<exceptions::LicenseException> currentException;
std::recursive_mutex lock;
protocol::RequestState state = protocol::UNCONNECTED;
sockaddr_in remote_address;
std::string buffer{};
int file_descriptor{0};
std::thread event_dispatch{};
std::thread closeThread{};
struct event_base* event_base{nullptr};
struct event* event_read{nullptr};
struct event* event_write{nullptr};
TAILQ_HEAD(, ts::buffer::RawBuffer) writeQueue;
std::string cryptKey = "";
void beginRequest();
void handleConnected();
static void handleEventRead(int, short, void*);
static void handleEventWrite(int, short, void*);
void handleMessage(const std::string&);
void disconnect(const std::string&);
void closeConnection();
void handlePacketHandshake(const std::string&);
void handlePacketDisconnect(const std::string&);
void handlePacketLicenseInfo(const std::string&);
void handlePacketInfoAdjustment(const std::string&);
};
}

View File

@ -1,133 +0,0 @@
#include <misc/endianness.h>
#include <LicenseRequest.pb.h>
#define DEFINE_HELPER
#include "LicenseRequest.h"
using namespace license;
using namespace std;
using namespace std::chrono;
void LicenceRequest::handlePacketDisconnect(const std::string& message) {
if(this->state != protocol::DISCONNECTING) {
/*
* We got an early disconnect.
* Test if we have a result. If so and the license is invalid then we could use that result
*/
if(this->response && !this->response->license_valid) {
try {
this->currentFuture->executionSucceed(this->response);
} catch(threads::InvalidFutureException& ex) {}
} else {
LICENSE_FERR(this, UnexcpectedDisconnectException, "Remote side closed the connection unexpectedly (" + message + ")");
}
}
}
void LicenceRequest::handlePacketHandshake(const std::string& data) {
if(this->state != protocol::HANDSCHAKE) LICENSE_FERR(this, InvalidResponseException, "Protocol state mismatch");
if(data.length() < 3) LICENSE_FERR(this, InvalidResponseException, "Invalid packet size");
if((uint8_t) data[0] != 0xAF || (uint8_t) data[1] != 0xFE) LICENSE_FERR(this, InvalidResponseException, "Invalid handshake");
if((uint8_t) data[2] != LICENSE_PROT_VERSION) LICENSE_FERR(this, InvalidResponseException, "Invalid license protocol version. Please update TeaSpeak!");
auto key_length = be2le16(data.data(), 3);
if(data.length() < key_length + 3) LICENSE_FERR(this, InvalidResponseException, "Invalid packet size");
this->cryptKey = data.substr(5, key_length);
ts::proto::license::ServerValidation request;
if(this->data->license) {
request.set_licensed(true);
request.set_license_info(true);
request.set_license(exportLocalLicense(this->data->license));
} else {
request.set_licensed(false);
request.set_license_info(false);
}
request.mutable_info()->set_uname(this->data->info->uname);
request.mutable_info()->set_version(this->data->info->version);
request.mutable_info()->set_timestamp(this->data->info->timestamp);
request.mutable_info()->set_unique_id(this->data->info->unique_identifier);
this->sendPacket(protocol::packet{protocol::PACKET_CLIENT_SERVER_VALIDATION, request});
this->state = protocol::LICENSE_INFO;
}
void LicenceRequest::handlePacketLicenseInfo(const std::string& message) {
ts::proto::license::LicenseResponse response{};
if(!response.ParseFromString(message)) LICENSE_FERR(this, InvalidResponseException, "Could not parse response");
auto result = make_shared<LicenseRequestResponse>();
auto licenseInfo = make_shared<LicenseInfo>();
if(!response.has_license_info() && this->data->license && response.valid() && response.blacklist().state() == ts::proto::license::VALID)
LICENSE_FERR(this, InvalidResponseException, "Missing license info");
if(this->data->license) {
licenseInfo->type = (LicenseType) response.license_info().type();
licenseInfo->email = response.license_info().email();
licenseInfo->username = response.license_info().username();
licenseInfo->first_name = response.license_info().first_name();
licenseInfo->last_name = response.license_info().last_name();
licenseInfo->creation = system_clock::time_point() + milliseconds(response.license_info().created());
licenseInfo->start = system_clock::time_point() + milliseconds(response.license_info().begin());
licenseInfo->end = system_clock::time_point() + milliseconds(response.license_info().end());
} else {
licenseInfo->type = LicenseType::DEMO;
licenseInfo->email = "license@teaspeak.de";
licenseInfo->username = "WolverinDEV";
licenseInfo->first_name = "Max";
licenseInfo->last_name = "Musterman";
licenseInfo->creation = system_clock::now();
licenseInfo->start = system_clock::now();
licenseInfo->end = system_clock::time_point();
}
result->license_valid = response.blacklist().state() == ts::proto::license::VALID; //TODO more detailed
result->age = system_clock::now();
result->license = licenseInfo;
this->response = result;
if(response.has_update_pending()) {
}
ts::proto::license::PropertyUpdateRequest infos{};
infos.set_speach_total(this->data->speach_total);
infos.set_speach_dead(this->data->speach_dead);
infos.set_speach_online(this->data->speach_online);
infos.set_speach_varianz(this->data->speach_varianz);
infos.set_clients_online(this->data->client_online);
infos.set_bots_online(this->data->bots_online);
infos.set_queries_online(this->data->queries_online);
infos.set_servers_online(this->data->servers_online);
infos.set_web_clients_online(this->data->web_clients_online);
infos.set_web_cert_revision(this->data->web_certificate_revision);
this->sendPacket({protocol::PACKET_CLIENT_PROPERTY_ADJUSTMENT, infos});
this->state = protocol::PROPERTY_ADJUSTMENT;
}
void LicenceRequest::handlePacketInfoAdjustment(const std::string& message) {
ts::proto::license::PropertyUpdateResponse response{};
if(!response.ParseFromString(message)) LICENSE_FERR(this, InvalidResponseException, "Could not parse response");
this->response->properties_valid = response.accepted();
this->response->speach_varianz_adjustment = response.speach_varianz_corrector();
this->response->speach_reset = response.reset_speach();
if(response.has_web_certificate() && this->callback_update_certificate) {
WebCertificate cert{};
cert.revision = response.web_certificate().revision();
cert.key = response.web_certificate().key();
cert.certificate = response.web_certificate().certificate();
this->callback_update_certificate(cert);
}
try {
this->currentFuture->executionSucceed(this->response);
} catch(threads::InvalidFutureException& ex) {}
this->response = nullptr;
this->disconnect("query succeeded!");
}

View File

@ -5,7 +5,7 @@
#include <functional>
#include <mutex>
#include "./License.h"
#include "license.h"
namespace license::client {
class LicenseServerClient {

View File

@ -7,7 +7,7 @@
#include <event.h>
#include <ThreadPool/ThreadHelper.h>
#include <misc/endianness.h>
#include "LicenseServerClient.h"
#include "shared/include/license/client.h"
#include "crypt.h"
using namespace license::client;

View File

@ -10,7 +10,7 @@
#include <ed25519/ge.h>
#include <ed25519/sc.h>
#include "crypt.h"
#include "License.h"
#include "shared/include/license/license.h"
using namespace std;
using namespace std::chrono;

View File

@ -263,10 +263,10 @@ target_link_libraries(TeaSpeakServer
libevent::core libevent::pthreads
opus::static
yaml-cpp
${LIBRARY_PATH_PROTOBUF}
#Require a so
sqlite3
DataPipes::rtc::shared
breakpad::static
protobuf::libprotobuf
@ -278,7 +278,6 @@ target_link_libraries(TeaSpeakServer
mysqlclient.a
jsoncpp_lib
${ed25519_LIBRARIES_STATIC}
${DataPipes_LIBRARIES_SHARED} # Also includes glib2.0
)
if (COMPILE_WEB_CLIENT)
@ -308,16 +307,4 @@ if (NOT DISABLE_JEMALLOC)
jemalloc
)
add_definitions(-DHAVE_JEMALLOC)
endif ()
#Fix RPATH
#patchelf --set-rpath ./libs/ TeaSpeakServer
#patchelf --remove-rpath TeaSpeakServer
#add_custom_command(
# TARGET TeaSpeakServer
## COMMAND bash -c "patchelf --set-rpath ./libs/ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}TeaSpeakServer"
# COMMAND bash -c "patchelf --remove-rpath ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}TeaSpeakServer"
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# COMMENT "Cleaning RPATH"
#)
endif ()

View File

@ -50,8 +50,8 @@ library_path=$(realpath "${library_base}/boringssl/${build_path}/crypto/libcrypt
cp "$library_path" . || { echo "failed to copy libcrypto.so"; exit 1; }
# Setting up DataPipes
library_path=$(realpath "${library_base}//DataPipes/${build_path}/lib/libDataPipes.so")
cp "$library_path" . || { echo "failed to copy libDataPipes.so"; exit 1; }
library_path=$(realpath "${library_base}/DataPipes/${build_path}/lib/libDataPipes-RTC.so")
cp "$library_path" . || { echo "failed to copy libDataPipes-RTC.so"; exit 1; }
_dp_path="$library_path"
# Setting up Sqlite3

View File

@ -2,7 +2,7 @@
#include "Configuration.h"
#include "build.h"
#include "../../license/shared/License.h"
#include "../../license/shared/include/license/license.h"
#include <yaml-cpp/yaml.h>
#include <fstream>
#include <deque>

View File

@ -8,7 +8,7 @@
#endif
#include <spdlog/common.h>
#include "geo/GeoLocation.h"
#include "../../license/shared/License.h"
#include "../../license/shared/include/license/license.h"
namespace YAML {
class Node;

View File

@ -4,7 +4,6 @@
#define XREALLOC undefined_realloc
#include <netdb.h>
#include "../../license/shared/LicenseRequest.h"
#include "src/weblist/WebListManager.h"
#include <log/LogUtils.h>
#include "InstanceHandler.h"
@ -23,6 +22,7 @@
#include <misc/rnd.h>
#include <misc/strobf.h>
#include <jemalloc/jemalloc.h>
#include <protocol/buffers.h>
#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE

View File

@ -7,11 +7,11 @@
#include <log/LogUtils.h>
#include <src/Configuration.h>
#include <src/ShutdownHelper.h>
#include "../../../license/shared/LicenseServerClient.h"
#include "../../../cmake-build-debug-wsl/license/LicenseRequest.pb.h"
#include <license/client.h>
#include "src/InstanceHandler.h"
#include "LicenseRequest.pb.h"
#define DO_LOCAL_REQUEST
//#define DO_LOCAL_REQUEST
using namespace ts::server::license;
LicenseService::LicenseService() {
@ -184,7 +184,7 @@ void LicenseService::handle_check_fail(const std::string &error) {
std::lock_guard rlock{this->request_lock};
this->abort_request(rlock, "request failed");
if(config::license->isPremium()) {
if(config::license->isPremium() && (this->timings.last_succeeded.time_since_epoch().count() == 0 || this->timings.failed_count < 6)) {
logCritical(LOG_INSTANCE, strobf("Failed to validate license:").string());
logCritical(LOG_INSTANCE, error);
logCritical(LOG_INSTANCE, strobf("Stopping server!").string());

View File

@ -193,8 +193,8 @@ namespace fs = std::experimental::filesystem;
0x555555c41ed7 ret
#endif
__attribute__((optimize("-O3"), always_inline)) void apply_crypt(void* source, void* target, size_t length, uint64_t base_key) {
uint64_t crypt_key = base_key;
size_t length_left = length;
uint64_t crypt_key{base_key};
size_t length_left{length};
auto source_ptr = (uint8_t*) source;
auto dest_ptr = (uint8_t*) target;

View File

@ -5,6 +5,7 @@
#include <chrono>
#include <mutex>
#include <deque>
#include <condition_variable>
struct event_base;
namespace ts {