Some minor changes

This commit is contained in:
WolverinDEV 2021-04-22 00:14:35 +02:00
parent f7039187b2
commit e99c1b442a
8 changed files with 50 additions and 38 deletions

@ -1 +1 @@
Subproject commit 401d248244b1d0dc82726d9baaeb375cb37f6f91 Subproject commit 50c0265be2f44dff2225d8e8a9c29514c95263c2

View File

@ -362,13 +362,14 @@ void QueryClient::handle_event_read(int fd, short, void *ptr_client) {
auto client = (QueryClient*) ptr_client; auto client = (QueryClient*) ptr_client;
auto length = read(fd, buffer, kReadBufferLength); auto length = read(fd, buffer, kReadBufferLength);
if(length <= 0){ if(length <= 0) {
if(errno == EINTR || errno == EAGAIN) { /* error handling */
if(length == -1 && errno == EAGAIN) {
/* Nothing to read */ /* Nothing to read */
return; return;
} }
if(length == 0 && errno == 0) { if(length == 0) {
logMessage(LOG_QUERY, "{} Connection closed. Client disconnected.", client->getLoggingPrefix()); logMessage(LOG_QUERY, "{} Connection closed. Client disconnected.", client->getLoggingPrefix());
} else { } else {
logMessage(LOG_QUERY, "{} Failed to received message ({}/{}). Closing connection.", client->getLoggingPrefix(), errno, strerror(errno)); logMessage(LOG_QUERY, "{} Failed to received message ({}/{}). Closing connection.", client->getLoggingPrefix(), errno, strerror(errno));

View File

@ -111,7 +111,6 @@ CryptSetupHandler::CommandResult CryptSetupHandler::handleCommandClientInitIv(co
client->properties()[property::CLIENT_TYPE_EXACT] = ClientType::CLIENT_TEASPEAK; client->properties()[property::CLIENT_TYPE_EXACT] = ClientType::CLIENT_TEASPEAK;
} }
/* normal TeamSpeak handling */
this->seed_client = base64::decode(cmd.value("alpha")); this->seed_client = base64::decode(cmd.value("alpha"));
if(this->seed_client.length() != 10) { if(this->seed_client.length() != 10) {
return ts::command_result{error::parameter_invalid, "alpha"}; return ts::command_result{error::parameter_invalid, "alpha"};
@ -122,30 +121,31 @@ CryptSetupHandler::CommandResult CryptSetupHandler::handleCommandClientInitIv(co
bool ot = cmd.has_key("ot") && cmd.value_as<bool>("ot"); bool ot = cmd.has_key("ot") && cmd.value_as<bool>("ot");
{ {
this->remote_key = std::shared_ptr<ecc_key>(new ecc_key{}, [](ecc_key* key){ auto remote_key_{new ecc_key{}};
if(!key) return; auto state = ecc_import((const unsigned char *) clientOmega.data(), clientOmega.length(), remote_key_);
ecc_free(key);
delete key;
});
auto state = ecc_import((const unsigned char *) clientOmega.data(), clientOmega.length(), &*this->remote_key);
if(state != CRYPT_OK) { if(state != CRYPT_OK) {
this->remote_key = nullptr; delete remote_key_;
return ts::command_result{error::client_could_not_validate_identity}; return ts::command_result{error::client_could_not_validate_identity};
} }
this->remote_key = std::shared_ptr<ecc_key>{remote_key_, [](ecc_key* key) {
if(!key) {
return;
}
/* We can only call ecc_free if we've really initialized the remote key */
ecc_free(key);
delete key;
}};
client->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = base64::encode(digest::sha1(cmd.value("omega"))); client->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = base64::encode(digest::sha1(cmd.value("omega")));
} }
this->new_protocol = !use_teaspeak && ot && config::experimental_31 && (this->client_protocol_time_ >= 173265950ULL || this->client_protocol_time_ == (uint32_t) 5680278000ULL); this->new_protocol = !use_teaspeak && ot && config::experimental_31 && (this->client_protocol_time_ >= 173265950ULL || this->client_protocol_time_ == (uint32_t) 5680278000ULL);
{ this->seed_server.resize(this->new_protocol ? 54 : 10);
size_t server_seed_length = this->new_protocol ? 54 : 10; for(auto& byte : this->seed_server) {
byte = (uint8_t) rand();
char beta[server_seed_length];
generate_random((uint8_t *) beta, server_seed_length);
this->seed_server = std::string{beta, server_seed_length};
} }
auto server_public_key = client->getServer()->publicServerKey(); auto server_public_key = client->getServer()->publicServerKey();
@ -164,7 +164,7 @@ CryptSetupHandler::CommandResult CryptSetupHandler::handleCommandClientInitIv(co
auto crypto_chain = this->chain_data->chain->exportChain(); auto crypto_chain = this->chain_data->chain->exportChain();
auto crypto_chain_hash = digest::sha256(crypto_chain); auto crypto_chain_hash = digest::sha256(crypto_chain);
size_t sign_buffer_size{128}; size_t sign_buffer_size{512};
char sign_buffer[sign_buffer_size]; char sign_buffer[sign_buffer_size];
prng_state prng_state{}; prng_state prng_state{};

View File

@ -490,7 +490,6 @@ void VoiceClient::send_video_unsupported_message() {
std::string message{kUnsupportedMessage}; std::string message{kUnsupportedMessage};
if(auto index{message.find("%web-url%")}; index != std::string::npos) { if(auto index{message.find("%web-url%")}; index != std::string::npos) {
/* TODO: generate connect url */ /* TODO: generate connect url */
//this->server->getWebServer()->
message.replace(index, 9, "https://web.teaspeak.de"); message.replace(index, 9, "https://web.teaspeak.de");
} }
notify.put_unchecked(0, "msg", message); notify.put_unchecked(0, "msg", message);

View File

@ -70,19 +70,22 @@ void WebClient::handleMessageRead(int fd, short, void *ptr_client) {
uint8_t buffer[buffer_length]; uint8_t buffer[buffer_length];
auto length = recv(fd, buffer, buffer_length, MSG_NOSIGNAL | MSG_DONTWAIT); auto length = recv(fd, buffer, buffer_length, MSG_NOSIGNAL | MSG_DONTWAIT);
if(length <= 0){ if(length <= 0) {
if(errno == EINTR || errno == EAGAIN) /* error handling "slow path" */
; if(length == 0 && errno == EAGAIN) {
else { /* We've currently no data queued */
debugMessage(client->getServerId(), "[{}] Failed to read message (length {}, errno {}, message: {}). Closing connection.", client->getLoggingPrefix(), length, errno, strerror(errno)); return;
{
lock_guard lock(client->event_mutex);
if(client->readEvent)
event_del_noblock(client->readEvent);
}
client->close_connection(system_clock::now()); /* direct close, but from another thread */
} }
debugMessage(client->getServerId(), "[{}] Failed to read message (length {}, errno {}, message: {}). Closing connection.", client->getLoggingPrefix(), length, errno, strerror(errno));
{
lock_guard lock{client->event_mutex};
if(client->readEvent) {
event_del_noblock(client->readEvent);
}
}
client->close_connection(system_clock::now()); /* direct close, but from another thread */
return; return;
} }

View File

@ -141,9 +141,11 @@ bool TeamSpeakLicense::load(std::string& error) {
} }
std::shared_ptr<LicenseChainData> TeamSpeakLicense::license(bool copy) { std::shared_ptr<LicenseChainData> TeamSpeakLicense::license(bool copy) {
if(!copy || !this->data) return this->data; if(!copy || !this->data) {
return this->data;
}
auto result = make_shared<LicenseChainData>(); auto result = std::make_shared<LicenseChainData>();
result->chain = this->data->chain->copy(); result->chain = this->data->chain->copy();
result->root_index = this->data->root_index; result->root_index = this->data->root_index;

View File

@ -118,6 +118,8 @@ bool VoiceServerSocket::activate(std::string &error) {
this->network_events.emplace_back(std::move(events)); this->network_events.emplace_back(std::move(events));
} }
network_loop->free_use_list(read_use_list);
network_loop->free_use_list(write_use_list);
if(this->network_events.empty()) { if(this->network_events.empty()) {
error = "failed to register any network events"; error = "failed to register any network events";
goto bind_failed; goto bind_failed;
@ -410,10 +412,15 @@ void VoiceServerSocket::network_event_read(int, short, void *ptr_network_events)
logCritical(socket->server_id, "Could not receive datagram packet! Code: {} Reason: {}", errno, strerror(errno)); logCritical(socket->server_id, "Could not receive datagram packet! Code: {} Reason: {}", errno, strerror(errno));
break; break;
} else if(bytes_read == 0){ } else if(bytes_read == 0){
//This should never happen /* We received a dara gram with zero length? Well, how the hell sends us such? */
break; break;
} }
if(bytes_read < 8) {
/* every packet must be at least 8 bytes long... */
continue;
}
if(*(uint64_t*) raw_read_buffer == TS3INIT.integral) { if(*(uint64_t*) raw_read_buffer == TS3INIT.integral) {
//Handle ddos protection... //Handle ddos protection...
/* TODO: Don't pass the raw buffer instead pass the protocol::ClientPacketParser and ClientPacketParser mus allow the INIT packet */ /* TODO: Don't pass the raw buffer instead pass the protocol::ClientPacketParser and ClientPacketParser mus allow the INIT packet */

2
shared

@ -1 +1 @@
Subproject commit f008d3a711307307a85bac837d124baf99d9e8ac Subproject commit bc8f314623ac341631ceb847ededcadb33926639