mirror of
https://github.com/overte-org/overte.git
synced 2025-07-10 18:58:37 +02:00
Fix obfuscation
This commit is contained in:
parent
bf5a65ca45
commit
c29ad09306
3 changed files with 44 additions and 19 deletions
|
@ -11,6 +11,10 @@
|
||||||
|
|
||||||
#include "Packet.h"
|
#include "Packet.h"
|
||||||
|
|
||||||
|
#include <LogHandler.h>
|
||||||
|
|
||||||
|
#include "SaltShaker.h"
|
||||||
|
|
||||||
using namespace udt;
|
using namespace udt;
|
||||||
|
|
||||||
static int packetMetaTypeId = qRegisterMetaType<Packet*>("Packet*");
|
static int packetMetaTypeId = qRegisterMetaType<Packet*>("Packet*");
|
||||||
|
@ -68,6 +72,26 @@ Packet::Packet(std::unique_ptr<char[]> data, qint64 size, const HifiSockAddr& se
|
||||||
{
|
{
|
||||||
readHeader();
|
readHeader();
|
||||||
|
|
||||||
|
if (getObfuscationLevel() != Packet::NoObfuscation) {
|
||||||
|
SaltShaker shaker;
|
||||||
|
shaker.unsalt(*this, getObfuscationLevel());
|
||||||
|
readHeader(); // read packet header again as some of the data was obfuscated
|
||||||
|
|
||||||
|
QString debugString = "Unobfuscating packet %1 with level %2";
|
||||||
|
debugString = debugString.arg(QString::number((uint32_t)getSequenceNumber()),
|
||||||
|
QString::number(getObfuscationLevel()));
|
||||||
|
|
||||||
|
if (isPartOfMessage()) {
|
||||||
|
debugString += "\n";
|
||||||
|
debugString += " Message Number: %1, Part Number: %2.";
|
||||||
|
debugString = debugString.arg(QString::number(getMessageNumber()),
|
||||||
|
QString::number(getMessagePartNumber()));
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString repeatedMessage = LogHandler::getInstance().addRepeatedMessageRegex("^Unobfuscating packet .{0,1000}");
|
||||||
|
qDebug() << qPrintable(debugString);
|
||||||
|
}
|
||||||
|
|
||||||
adjustPayloadStartAndCapacity(Packet::localHeaderSize(_isPartOfMessage), _payloadSize > 0);
|
adjustPayloadStartAndCapacity(Packet::localHeaderSize(_isPartOfMessage), _payloadSize > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ static const std::array<Key, 4> KEYS {{
|
||||||
0x54c92e8d2c871642
|
0x54c92e8d2c871642
|
||||||
}};
|
}};
|
||||||
|
|
||||||
void saltingHelper(char* start, int size, Key key) {;
|
void saltingHelper(char* start, int size, Key key) {
|
||||||
const auto end = start + size;
|
const auto end = start + size;
|
||||||
|
|
||||||
auto p = start;
|
auto p = start;
|
||||||
|
@ -42,13 +42,13 @@ std::unique_ptr<Packet> SaltShaker::salt(const Packet& packet, unsigned int salt
|
||||||
Q_ASSERT_X(saltiness < KEYS.size(), Q_FUNC_INFO, "");
|
Q_ASSERT_X(saltiness < KEYS.size(), Q_FUNC_INFO, "");
|
||||||
|
|
||||||
auto copy = Packet::createCopy(packet);
|
auto copy = Packet::createCopy(packet);
|
||||||
saltingHelper(copy->getPayload(), copy->getPayloadSize(), KEYS[saltiness]);
|
|
||||||
copy->writeSequenceNumber(copy->getSequenceNumber(), (Packet::ObfuscationLevel)saltiness);
|
copy->writeSequenceNumber(copy->getSequenceNumber(), (Packet::ObfuscationLevel)saltiness);
|
||||||
|
saltingHelper(copy->getData() + 4, copy->getDataSize() - 4, KEYS[saltiness]);
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void unsalt(Packet& packet, unsigned int saltiness) {
|
void SaltShaker::unsalt(Packet& packet, unsigned int saltiness) {
|
||||||
Q_ASSERT_X(saltiness < KEYS.size(), Q_FUNC_INFO, "");
|
Q_ASSERT_X(saltiness < KEYS.size(), Q_FUNC_INFO, "");
|
||||||
|
|
||||||
saltingHelper(packet.getPayload(), packet.getPayloadSize(), KEYS[saltiness]);
|
saltingHelper(packet.getData() + 4, packet.getDataSize() - 4, KEYS[saltiness]);
|
||||||
}
|
}
|
|
@ -338,6 +338,8 @@ bool SendQueue::maybeSendNewPacket() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <LogHandler.h>
|
||||||
|
|
||||||
bool SendQueue::maybeResendPacket() {
|
bool SendQueue::maybeResendPacket() {
|
||||||
|
|
||||||
// the following while makes sure that we find a packet to re-send, if there is one
|
// the following while makes sure that we find a packet to re-send, if there is one
|
||||||
|
@ -362,27 +364,26 @@ bool SendQueue::maybeResendPacket() {
|
||||||
auto& resendPacket = *(entry.second);
|
auto& resendPacket = *(entry.second);
|
||||||
++entry.first; // Add 1 resend
|
++entry.first; // Add 1 resend
|
||||||
|
|
||||||
static const int OBFUSCATION_THRESHOLD = 3;
|
auto saltiness = entry.first < 2 ? 0 : (entry.first - 2) % 4;
|
||||||
if (entry.first > OBFUSCATION_THRESHOLD) {
|
|
||||||
|
|
||||||
if (entry.first % OBFUSCATION_THRESHOLD == 0) {
|
if (saltiness != 0) {
|
||||||
QString debugString = "Obfuscating packet %1 with level %2 for the first time.";
|
QString debugString = "Obfuscating packet %1 with level %2";
|
||||||
debugString = debugString.arg((uint32_t)resendPacket.getSequenceNumber(),
|
debugString = debugString.arg(QString::number((uint32_t)resendPacket.getSequenceNumber()),
|
||||||
entry.first / OBFUSCATION_THRESHOLD);
|
QString::number(saltiness));
|
||||||
|
|
||||||
if (resendPacket.isPartOfMessage()) {
|
if (resendPacket.isPartOfMessage()) {
|
||||||
debugString += "\n";
|
debugString += "\n";
|
||||||
debugString += " Message Number: %1, Part Number: %2.";
|
debugString += " Message Number: %1, Part Number: %2.";
|
||||||
debugString = debugString.arg(resendPacket.getMessageNumber(),
|
debugString = debugString.arg(QString::number(resendPacket.getMessageNumber()),
|
||||||
resendPacket.getMessagePartNumber());
|
QString::number(resendPacket.getMessagePartNumber()));
|
||||||
}
|
|
||||||
|
|
||||||
qCritical() << qPrintable(debugString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static QString repeatedMessage = LogHandler::getInstance().addRepeatedMessageRegex("^Obfuscating packet .{0,1000}");
|
||||||
|
qCritical() << qPrintable(debugString);
|
||||||
|
|
||||||
SaltShaker shaker;
|
SaltShaker shaker;
|
||||||
auto packet = shaker.salt(resendPacket, glm::min(entry.first / OBFUSCATION_THRESHOLD, 3));
|
auto packet = shaker.salt(resendPacket, saltiness);
|
||||||
|
|
||||||
// unlock the sent packets
|
// unlock the sent packets
|
||||||
sentLocker.unlock();
|
sentLocker.unlock();
|
||||||
|
|
Loading…
Reference in a new issue