General fixes

Fixed most compiler warnings. Changed used interface from utun0/utun1 to lynx0
This commit is contained in:
2025-11-27 18:43:09 +01:00
parent d2242ebbc7
commit 2a2deae022
10 changed files with 63 additions and 28 deletions

View File

@@ -47,9 +47,14 @@ namespace ColumnLynx::Utils {
mPublicKey = pk; mPublicKey = pk;
mPrivateKey = sk; mPrivateKey = sk;
int r;
// Convert to Curve25519 keys for encryption // Convert to Curve25519 keys for encryption
crypto_sign_ed25519_pk_to_curve25519(mXPublicKey.data(), mPublicKey.data()); r = crypto_sign_ed25519_pk_to_curve25519(mXPublicKey.data(), mPublicKey.data());
crypto_sign_ed25519_sk_to_curve25519(mXPrivateKey.data(), mPrivateKey.data()); r = crypto_sign_ed25519_sk_to_curve25519(mXPrivateKey.data(), mPrivateKey.data());
if (r != 0) {
throw std::runtime_error("Conversion of signing keys to encryption keys failed!");
}
} }
// Helper section // Helper section

View File

@@ -122,9 +122,9 @@ namespace ColumnLynx::Net {
if (mSessionIPs.find(candidateIP) == mSessionIPs.end()) { if (mSessionIPs.find(candidateIP) == mSessionIPs.end()) {
return candidateIP; return candidateIP;
} }
return 0; // Unavailable
} }
return 0; // Unavailable
} }
// Lock an IP as assigned to a specific session // Lock an IP as assigned to a specific session

View File

@@ -66,7 +66,7 @@ int main(int argc, char** argv) {
WintunInitialize(); WintunInitialize();
#endif #endif
std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>("utun1"); std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>("lynx0");
log("Using virtual interface: " + tun->getName()); log("Using virtual interface: " + tun->getName());
LibSodiumWrapper sodiumWrapper = LibSodiumWrapper(); LibSodiumWrapper sodiumWrapper = LibSodiumWrapper();

View File

@@ -196,7 +196,12 @@ namespace ColumnLynx::Net::TCP {
// Convert the server's public key to Curve25519 for encryption // Convert the server's public key to Curve25519 for encryption
AsymPublicKey serverXPubKey{}; AsymPublicKey serverXPubKey{};
crypto_sign_ed25519_pk_to_curve25519(serverXPubKey.data(), mServerPublicKey); int r = crypto_sign_ed25519_pk_to_curve25519(serverXPubKey.data(), mServerPublicKey);
if (r != 0) {
Utils::error("Failed to convert server signing key to encryption key! Killing connection.");
disconnect();
return;
}
// Generate AES key and send confirmation // Generate AES key and send confirmation
mConnectionAESKey = Utils::LibSodiumWrapper::generateRandom256Bit(); mConnectionAESKey = Utils::LibSodiumWrapper::generateRandom256Bit();

View File

@@ -16,9 +16,14 @@ namespace ColumnLynx::Utils {
throw std::runtime_error("Failed to generate key pair"); throw std::runtime_error("Failed to generate key pair");
} }
int r;
// Convert to Curve25519 keys for encryption // Convert to Curve25519 keys for encryption
crypto_sign_ed25519_pk_to_curve25519(mXPublicKey.data(), mPublicKey.data()); r = crypto_sign_ed25519_pk_to_curve25519(mXPublicKey.data(), mPublicKey.data());
crypto_sign_ed25519_sk_to_curve25519(mXPrivateKey.data(), mPrivateKey.data()); r = crypto_sign_ed25519_sk_to_curve25519(mXPrivateKey.data(), mPrivateKey.data());
if (r != 0) {
throw std::runtime_error("Conversion of signing keys to encryption keys failed!");
}
log("Libsodium initialized and keypair generated"); log("Libsodium initialized and keypair generated");
} }

View File

@@ -133,7 +133,7 @@ namespace ColumnLynx::Utils {
std::unordered_map<std::string, std::string> config; std::unordered_map<std::string, std::string> config;
char delimiter = '='; char delimiter = '=';
for (std::string str : readLines) { for (std::string &str : readLines) {
std::stringstream ss(str); std::stringstream ss(str);
std::string key; std::string key;

View File

@@ -42,7 +42,7 @@ namespace ColumnLynx::Net {
sc.sc_family = AF_SYSTEM; sc.sc_family = AF_SYSTEM;
sc.ss_sysaddr = AF_SYS_CONTROL; sc.ss_sysaddr = AF_SYS_CONTROL;
sc.sc_id = ctlInfo.ctl_id; sc.sc_id = ctlInfo.ctl_id;
sc.sc_unit = 0; // utun0 (0 = auto-assign) sc.sc_unit = 0; // lynx0 (0 = auto-assign)
if (connect(mFd, (struct sockaddr*)&sc, sizeof(sc)) < 0) { if (connect(mFd, (struct sockaddr*)&sc, sizeof(sc)) < 0) {
if (errno == EPERM) if (errno == EPERM)
@@ -188,11 +188,12 @@ namespace ColumnLynx::Net {
std::string ipStr = ipv4ToString(clientIP); std::string ipStr = ipv4ToString(clientIP);
std::string peerStr = ipv4ToString(serverIP); std::string peerStr = ipv4ToString(serverIP);
std::string prefixStr = ipv4ToString(prefixLen);
// Set netmask (/24 CIDR temporarily with raw command, improve later) // Set netmask (/24 CIDR temporarily with raw command, improve later)
snprintf(cmd, sizeof(cmd), snprintf(cmd, sizeof(cmd),
"ifconfig utun0 %s %s mtu %d netmask 255.255.255.0 up", "ifconfig lynx0 %s %s mtu %d netmask %s up",
ipStr.c_str(), peerStr.c_str(), mtu); ipStr.c_str(), peerStr.c_str(), mtu, prefixStr.c_str());
system(cmd); system(cmd);
Utils::log("Executed command: " + std::string(cmd)); Utils::log("Executed command: " + std::string(cmd));
@@ -203,20 +204,34 @@ namespace ColumnLynx::Net {
// ------------------------------------------------------------ // ------------------------------------------------------------
// Windows (Wintun) // Windows (Wintun)
// ------------------------------------------------------------ // ------------------------------------------------------------
bool VirtualInterface::mApplyWindowsIP(uint32_t clientIP, uint32_t serverIP, bool VirtualInterface::mApplyWindowsIP(uint32_t clientIP,
uint8_t prefixLen, uint16_t mtu) uint32_t serverIP,
uint8_t prefixLen,
uint16_t mtu)
{ {
#ifdef _WIN32 #ifdef _WIN32
char ip[32], gw[32]; std::string ip = ipv4ToString(clientIP);
strcpy(ip, ipv4ToString(clientIP).c_str()); std::string gw = ipv4ToString(serverIP);
strcpy(gw, ipv4ToString(serverIP).c_str()); std::string mask;
// Convert prefixLen → subnet mask
uint32_t maskInt = (prefixLen == 0) ? 0 : (0xFFFFFFFF << (32 - prefixLen));
mask = ipv4ToString(maskInt);
char cmd[256]; char cmd[256];
// 1. Set the static IP + mask + gateway
snprintf(cmd, sizeof(cmd), snprintf(cmd, sizeof(cmd),
"netsh interface ip set address name=\"%s\" static %s %d.%d.%d.%d", "netsh interface ip set address name=\"%s\" static %s %s %s",
mIfName.c_str(), ip, mIfName.c_str(), ip.c_str(), mask.c_str(), gw.c_str()
(prefixLen <= 8) ? ((prefixLen << 3) & 255) : 255, );
255, 255, 255); system(cmd);
// 2. Set MTU (separate command)
snprintf(cmd, sizeof(cmd),
"netsh interface ipv4 set subinterface \"%s\" mtu=%u store=persistent",
mIfName.c_str(), mtu
);
system(cmd); system(cmd);
return true; return true;

View File

@@ -66,7 +66,7 @@ int main(int argc, char** argv) {
WintunInitialize(); WintunInitialize();
#endif #endif
std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>("utun0"); std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>("lynx0");
log("Using virtual interface: " + tun->getName()); log("Using virtual interface: " + tun->getName());
// Generate a temporary keypair, replace with actual CA signed keys later (Note, these are stored in memory) // Generate a temporary keypair, replace with actual CA signed keys later (Note, these are stored in memory)

View File

@@ -118,7 +118,14 @@ namespace ColumnLynx::Net::TCP {
std::memcpy(signPk.data(), data.data() + 1, std::min(data.size() - 1, sizeof(signPk))); std::memcpy(signPk.data(), data.data() + 1, std::min(data.size() - 1, sizeof(signPk)));
// We can safely store this without further checking, the client will need to send the encrypted AES key in a way where they must possess the corresponding private key anyways. // We can safely store this without further checking, the client will need to send the encrypted AES key in a way where they must possess the corresponding private key anyways.
crypto_sign_ed25519_pk_to_curve25519(mConnectionPublicKey.data(), signPk.data()); // Store the client's public encryption key key (for identification) int r = crypto_sign_ed25519_pk_to_curve25519(mConnectionPublicKey.data(), signPk.data()); // Store the client's public encryption key key (for identification)
if (r != 0) {
Utils::error("Conversion of client signing key to encryption key failed! Killing connection from " + reqAddr);
disconnect();
return;
}
Utils::debug("Client " + reqAddr + " converted public encryption key: " + Utils::bytesToHexString(mConnectionPublicKey.data(), 32)); Utils::debug("Client " + reqAddr + " converted public encryption key: " + Utils::bytesToHexString(mConnectionPublicKey.data(), 32));
Utils::debug("Key attempted connect: " + Utils::bytesToHexString(signPk.data(), signPk.size())); Utils::debug("Key attempted connect: " + Utils::bytesToHexString(signPk.data(), signPk.size()));

View File

@@ -2,8 +2,6 @@
// Copyright (C) 2025 DcruBro // Copyright (C) 2025 DcruBro
// Distributed under the terms of the GNU General Public License, either version 2 only or version 3. See LICENSES/ for details. // Distributed under the terms of the GNU General Public License, either version 2 only or version 3. See LICENSES/ for details.
#pragma once
#include <columnlynx/server/net/tcp/tcp_server.hpp> #include <columnlynx/server/net/tcp/tcp_server.hpp>
#include <cstdint> #include <cstdint>
@@ -63,7 +61,7 @@ namespace ColumnLynx::Net::TCP {
// Snapshot to avoid iterator invalidation while callbacks erase() // Snapshot to avoid iterator invalidation while callbacks erase()
std::vector<std::shared_ptr<TCPConnection>> snapshot(mClients.begin(), mClients.end()); std::vector<std::shared_ptr<TCPConnection>> snapshot(mClients.begin(), mClients.end());
for (auto& client : snapshot) { for (auto &client : snapshot) {
try { try {
client->disconnect(); // should shutdown+close the socket client->disconnect(); // should shutdown+close the socket
Utils::log("GRACEFUL_DISCONNECT sent to session: " + std::to_string(client->getSessionID())); Utils::log("GRACEFUL_DISCONNECT sent to session: " + std::to_string(client->getSessionID()));