2019-07-17 13:37:18 -04:00
|
|
|
#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) {
|
2019-08-25 16:16:42 -04:00
|
|
|
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) {
|
|
|
|
this->currentFuture->executionSucceed(this->response);
|
|
|
|
} else {
|
|
|
|
LICENSE_FERR(this, UnexcpectedDisconnectException, "Remote side closed the connection unexpectedly (" + message + ")");
|
|
|
|
}
|
|
|
|
}
|
2019-07-17 13:37:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LicenceRequest::handlePacketHandshake(const std::string& data) {
|
|
|
|
if(this->state != protocol::HANDSCAKE) 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>();
|
2019-08-25 16:16:42 -04:00
|
|
|
if(!response.has_license_info() && this->data->license && response.valid() && response.blacklist().state() == ts::proto::license::VALID) {
|
|
|
|
LICENSE_FERR(this, InvalidResponseException, "Missing license info");
|
|
|
|
}
|
2019-07-17 13:37:18 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
2019-11-22 14:51:00 -05:00
|
|
|
|
|
|
|
infos.set_web_cert_revision(this->data->web_certificate_revision);
|
2019-07-17 13:37:18 -04:00
|
|
|
this->sendPacket({protocol::PACKET_CLIENT_PROPERTY_ADJUSTMENT, infos});
|
|
|
|
this->state = protocol::PROPERTY_ADJUSTMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LicenceRequest::handlePacketInfoAdjustment(const std::string& message) {
|
2019-11-22 14:51:00 -05:00
|
|
|
ts::proto::license::PropertyUpdateResponse response{};
|
2019-07-17 13:37:18 -04:00
|
|
|
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();
|
2019-11-22 14:51:00 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-07-17 13:37:18 -04:00
|
|
|
this->currentFuture->executionSucceed(this->response);
|
|
|
|
this->response = nullptr;
|
|
|
|
|
|
|
|
this->disconnect("query succeeded!");
|
|
|
|
}
|