General fixes
Fixed most compiler warnings. Changed used interface from utun0/utun1 to lynx0
This commit is contained in:
@@ -47,9 +47,14 @@ namespace ColumnLynx::Utils {
|
||||
mPublicKey = pk;
|
||||
mPrivateKey = sk;
|
||||
|
||||
int r;
|
||||
// Convert to Curve25519 keys for encryption
|
||||
crypto_sign_ed25519_pk_to_curve25519(mXPublicKey.data(), mPublicKey.data());
|
||||
crypto_sign_ed25519_sk_to_curve25519(mXPrivateKey.data(), mPrivateKey.data());
|
||||
r = crypto_sign_ed25519_pk_to_curve25519(mXPublicKey.data(), mPublicKey.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
|
||||
|
||||
@@ -122,9 +122,9 @@ namespace ColumnLynx::Net {
|
||||
if (mSessionIPs.find(candidateIP) == mSessionIPs.end()) {
|
||||
return candidateIP;
|
||||
}
|
||||
|
||||
return 0; // Unavailable
|
||||
}
|
||||
|
||||
return 0; // Unavailable
|
||||
}
|
||||
|
||||
// Lock an IP as assigned to a specific session
|
||||
|
||||
@@ -66,7 +66,7 @@ int main(int argc, char** argv) {
|
||||
WintunInitialize();
|
||||
#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());
|
||||
|
||||
LibSodiumWrapper sodiumWrapper = LibSodiumWrapper();
|
||||
|
||||
@@ -196,7 +196,12 @@ namespace ColumnLynx::Net::TCP {
|
||||
|
||||
// Convert the server's public key to Curve25519 for encryption
|
||||
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
|
||||
mConnectionAESKey = Utils::LibSodiumWrapper::generateRandom256Bit();
|
||||
|
||||
@@ -16,9 +16,14 @@ namespace ColumnLynx::Utils {
|
||||
throw std::runtime_error("Failed to generate key pair");
|
||||
}
|
||||
|
||||
int r;
|
||||
// Convert to Curve25519 keys for encryption
|
||||
crypto_sign_ed25519_pk_to_curve25519(mXPublicKey.data(), mPublicKey.data());
|
||||
crypto_sign_ed25519_sk_to_curve25519(mXPrivateKey.data(), mPrivateKey.data());
|
||||
r = crypto_sign_ed25519_pk_to_curve25519(mXPublicKey.data(), mPublicKey.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");
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace ColumnLynx::Utils {
|
||||
std::unordered_map<std::string, std::string> config;
|
||||
char delimiter = '=';
|
||||
|
||||
for (std::string str : readLines) {
|
||||
for (std::string &str : readLines) {
|
||||
std::stringstream ss(str);
|
||||
|
||||
std::string key;
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace ColumnLynx::Net {
|
||||
sc.sc_family = AF_SYSTEM;
|
||||
sc.ss_sysaddr = AF_SYS_CONTROL;
|
||||
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 (errno == EPERM)
|
||||
@@ -188,11 +188,12 @@ namespace ColumnLynx::Net {
|
||||
|
||||
std::string ipStr = ipv4ToString(clientIP);
|
||||
std::string peerStr = ipv4ToString(serverIP);
|
||||
std::string prefixStr = ipv4ToString(prefixLen);
|
||||
|
||||
// Set netmask (/24 CIDR temporarily with raw command, improve later)
|
||||
snprintf(cmd, sizeof(cmd),
|
||||
"ifconfig utun0 %s %s mtu %d netmask 255.255.255.0 up",
|
||||
ipStr.c_str(), peerStr.c_str(), mtu);
|
||||
"ifconfig lynx0 %s %s mtu %d netmask %s up",
|
||||
ipStr.c_str(), peerStr.c_str(), mtu, prefixStr.c_str());
|
||||
system(cmd);
|
||||
|
||||
Utils::log("Executed command: " + std::string(cmd));
|
||||
@@ -203,20 +204,34 @@ namespace ColumnLynx::Net {
|
||||
// ------------------------------------------------------------
|
||||
// Windows (Wintun)
|
||||
// ------------------------------------------------------------
|
||||
bool VirtualInterface::mApplyWindowsIP(uint32_t clientIP, uint32_t serverIP,
|
||||
uint8_t prefixLen, uint16_t mtu)
|
||||
bool VirtualInterface::mApplyWindowsIP(uint32_t clientIP,
|
||||
uint32_t serverIP,
|
||||
uint8_t prefixLen,
|
||||
uint16_t mtu)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char ip[32], gw[32];
|
||||
strcpy(ip, ipv4ToString(clientIP).c_str());
|
||||
strcpy(gw, ipv4ToString(serverIP).c_str());
|
||||
std::string ip = ipv4ToString(clientIP);
|
||||
std::string gw = ipv4ToString(serverIP);
|
||||
std::string mask;
|
||||
|
||||
// Convert prefixLen → subnet mask
|
||||
uint32_t maskInt = (prefixLen == 0) ? 0 : (0xFFFFFFFF << (32 - prefixLen));
|
||||
mask = ipv4ToString(maskInt);
|
||||
|
||||
char cmd[256];
|
||||
|
||||
// 1. Set the static IP + mask + gateway
|
||||
snprintf(cmd, sizeof(cmd),
|
||||
"netsh interface ip set address name=\"%s\" static %s %d.%d.%d.%d",
|
||||
mIfName.c_str(), ip,
|
||||
(prefixLen <= 8) ? ((prefixLen << 3) & 255) : 255,
|
||||
255, 255, 255);
|
||||
"netsh interface ip set address name=\"%s\" static %s %s %s",
|
||||
mIfName.c_str(), ip.c_str(), mask.c_str(), gw.c_str()
|
||||
);
|
||||
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);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -66,7 +66,7 @@ int main(int argc, char** argv) {
|
||||
WintunInitialize();
|
||||
#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());
|
||||
|
||||
// Generate a temporary keypair, replace with actual CA signed keys later (Note, these are stored in memory)
|
||||
|
||||
@@ -118,7 +118,14 @@ namespace ColumnLynx::Net::TCP {
|
||||
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.
|
||||
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("Key attempted connect: " + Utils::bytesToHexString(signPk.data(), signPk.size()));
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <columnlynx/server/net/tcp/tcp_server.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
@@ -63,7 +61,7 @@ namespace ColumnLynx::Net::TCP {
|
||||
|
||||
// Snapshot to avoid iterator invalidation while callbacks erase()
|
||||
std::vector<std::shared_ptr<TCPConnection>> snapshot(mClients.begin(), mClients.end());
|
||||
for (auto& client : snapshot) {
|
||||
for (auto &client : snapshot) {
|
||||
try {
|
||||
client->disconnect(); // should shutdown+close the socket
|
||||
Utils::log("GRACEFUL_DISCONNECT sent to session: " + std::to_string(client->getSessionID()));
|
||||
|
||||
Reference in New Issue
Block a user