TESTING: protocol version 2
This commit is contained in:
@@ -35,7 +35,7 @@ namespace ColumnLynx {
|
||||
return getClientState()->virtualInterface;
|
||||
}
|
||||
|
||||
uint64_t ClientSession::getSessionID() const {
|
||||
uint32_t ClientSession::getSessionID() const {
|
||||
return getClientState()->sessionID;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace ColumnLynx {
|
||||
mClientState->virtualInterface = virtualInterface;
|
||||
}
|
||||
|
||||
void ClientSession::setSessionID(uint64_t sessionID) {
|
||||
void ClientSession::setSessionID(uint32_t sessionID) {
|
||||
std::unique_lock lock(mMutex);
|
||||
mClientState->sessionID = sessionID;
|
||||
}
|
||||
|
||||
@@ -104,6 +104,9 @@ int main(int argc, char** argv) {
|
||||
struct ClientState initialState{};
|
||||
initialState.configPath = configPath;
|
||||
initialState.insecureMode = insecureMode;
|
||||
initialState.send_cnt = 0;
|
||||
initialState.recv_cnt = 0;
|
||||
randombytes_buf(&initialState.noncePrefix, sizeof(uint32_t)); // Randomize nonce prefix
|
||||
|
||||
std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>(optionsObj["interface"].as<std::string>());
|
||||
log("Using virtual interface: " + tun->getName());
|
||||
@@ -116,7 +119,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
std::array<uint8_t, 32> aesKey = std::array<uint8_t, 32>();
|
||||
aesKey.fill(0); // Defualt zeroed state until modified by handshake
|
||||
uint64_t sessionID = 0;
|
||||
uint32_t sessionID = 0;
|
||||
initialState.aesKey = aesKey;
|
||||
initialState.sessionID = sessionID;
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace ColumnLynx::Net::TCP {
|
||||
std::memcpy(&mConnectionSessionID, decrypted.data(), sizeof(mConnectionSessionID));
|
||||
std::memcpy(&mTunConfig, decrypted.data() + sizeof(mConnectionSessionID), sizeof(Protocol::TunConfig));
|
||||
|
||||
mConnectionSessionID = Utils::cbe64toh(mConnectionSessionID);
|
||||
mConnectionSessionID = ntohl(mConnectionSessionID);
|
||||
|
||||
Utils::log("Connection established with Session ID: " + std::to_string(mConnectionSessionID));
|
||||
|
||||
|
||||
@@ -46,7 +46,12 @@ namespace ColumnLynx::Net::UDP {
|
||||
|
||||
void UDPClient::sendMessage(const std::string& data) {
|
||||
UDPPacketHeader hdr{};
|
||||
randombytes_buf(hdr.nonce.data(), hdr.nonce.size());
|
||||
uint8_t nonce[12];
|
||||
uint32_t prefix = ClientSession::getInstance().getNoncePrefix();
|
||||
uint64_t sendCount = ClientSession::getInstance().getSendCount();
|
||||
memcpy(nonce, &prefix, sizeof(uint32_t)); // Prefix nonce with client-specific random value
|
||||
memcpy(nonce + sizeof(uint32_t), &sendCount, sizeof(uint64_t)); // Use send count as nonce suffix to ensure uniqueness
|
||||
std::copy_n(nonce, 12, hdr.nonce.data());
|
||||
|
||||
if (ClientSession::getInstance().getAESKey().empty() || ClientSession::getInstance().getSessionID() == 0) {
|
||||
Utils::error("UDP Client AES key or Session ID reference is null!");
|
||||
@@ -62,7 +67,7 @@ namespace ColumnLynx::Net::UDP {
|
||||
);
|
||||
|
||||
std::vector<uint8_t> packet;
|
||||
packet.reserve(sizeof(UDPPacketHeader) + sizeof(uint64_t) + encryptedPayload.size());
|
||||
packet.reserve(sizeof(UDPPacketHeader) + encryptedPayload.size());
|
||||
packet.insert(packet.end(),
|
||||
reinterpret_cast<uint8_t*>(&hdr),
|
||||
reinterpret_cast<uint8_t*>(&hdr) + sizeof(UDPPacketHeader)
|
||||
@@ -76,6 +81,8 @@ namespace ColumnLynx::Net::UDP {
|
||||
|
||||
mSocket.send_to(asio::buffer(packet), mRemoteEndpoint);
|
||||
Utils::debug("Sent UDP packet of size " + std::to_string(packet.size()));
|
||||
|
||||
ClientSession::getInstance().incrementSendCount();
|
||||
}
|
||||
|
||||
void UDPClient::stop() {
|
||||
|
||||
Reference in New Issue
Block a user