Converted some raw pointers to smart pointers
This commit is contained in:
@@ -74,16 +74,17 @@ int main(int argc, char** argv) {
|
||||
std::shared_ptr<VirtualInterface> tun = std::make_shared<VirtualInterface>(optionsObj["interface"].as<std::string>());
|
||||
log("Using virtual interface: " + tun->getName());
|
||||
|
||||
LibSodiumWrapper sodiumWrapper = LibSodiumWrapper();
|
||||
debug("Public Key: " + Utils::bytesToHexString(sodiumWrapper.getPublicKey(), 32));
|
||||
debug("Private Key: " + Utils::bytesToHexString(sodiumWrapper.getPrivateKey(), 64));
|
||||
std::shared_ptr<LibSodiumWrapper> sodiumWrapper = std::make_shared<LibSodiumWrapper>();
|
||||
debug("Public Key: " + Utils::bytesToHexString(sodiumWrapper->getPublicKey(), 32));
|
||||
debug("Private Key: " + Utils::bytesToHexString(sodiumWrapper->getPrivateKey(), 64));
|
||||
|
||||
std::array<uint8_t, 32> aesKey = {0}; // Defualt zeroed state until modified by handshake
|
||||
uint64_t sessionID = 0;
|
||||
std::shared_ptr<std::array<uint8_t, 32>> aesKey = std::make_shared<std::array<uint8_t, 32>>();
|
||||
aesKey->fill(0); // Defualt zeroed state until modified by handshake
|
||||
std::shared_ptr<uint64_t> sessionID = std::make_shared<uint64_t>(0);
|
||||
|
||||
asio::io_context io;
|
||||
auto client = std::make_shared<ColumnLynx::Net::TCP::TCPClient>(io, host, port, &sodiumWrapper, &aesKey, &sessionID, &insecureMode, tun);
|
||||
auto udpClient = std::make_shared<ColumnLynx::Net::UDP::UDPClient>(io, host, port, &aesKey, &sessionID, tun);
|
||||
auto client = std::make_shared<ColumnLynx::Net::TCP::TCPClient>(io, host, port, sodiumWrapper, aesKey, sessionID, insecureMode, tun);
|
||||
auto udpClient = std::make_shared<ColumnLynx::Net::UDP::UDPClient>(io, host, port, aesKey, sessionID, tun);
|
||||
|
||||
client->start();
|
||||
udpClient->start();
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace ColumnLynx::Net::TCP {
|
||||
// Verify pubkey against whitelisted_keys
|
||||
std::vector<std::string> whitelistedKeys = Utils::getWhitelistedKeys();
|
||||
if (std::find(whitelistedKeys.begin(), whitelistedKeys.end(), Utils::bytesToHexString(mServerPublicKey, 32)) == whitelistedKeys.end()) { // Key verification is handled in later steps of the handshake
|
||||
if (!(*mInsecureMode)) {
|
||||
if (!mInsecureMode) {
|
||||
Utils::error("Server public key not in whitelisted_keys. Terminating connection.");
|
||||
disconnect();
|
||||
return;
|
||||
|
||||
@@ -36,10 +36,9 @@ namespace ColumnLynx::Net::UDP {
|
||||
reinterpret_cast<uint8_t*>(&hdr),
|
||||
reinterpret_cast<uint8_t*>(&hdr) + sizeof(UDPPacketHeader)
|
||||
);
|
||||
uint64_t sid = *mSessionIDRef;
|
||||
packet.insert(packet.end(),
|
||||
reinterpret_cast<uint8_t*>(&sid),
|
||||
reinterpret_cast<uint8_t*>(&sid) + sizeof(sid)
|
||||
reinterpret_cast<uint8_t*>(mSessionIDRef.get()),
|
||||
reinterpret_cast<uint8_t*>(mSessionIDRef.get()) + sizeof(uint64_t)
|
||||
);
|
||||
packet.insert(packet.end(), encryptedPayload.begin(), encryptedPayload.end());
|
||||
|
||||
@@ -90,6 +89,11 @@ namespace ColumnLynx::Net::UDP {
|
||||
uint64_t sessionID;
|
||||
std::memcpy(&sessionID, mRecvBuffer.data() + sizeof(UDPPacketHeader), sizeof(uint64_t));
|
||||
|
||||
if (sessionID != *mSessionIDRef) {
|
||||
Utils::warn("Got packet that isn't for me! Dropping!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Decrypt payload
|
||||
std::vector<uint8_t> ciphertext(
|
||||
mRecvBuffer.begin() + sizeof(UDPPacketHeader) + sizeof(uint64_t),
|
||||
|
||||
Reference in New Issue
Block a user