enforce unique ids
This commit is contained in:
@@ -78,6 +78,8 @@ namespace ColumnLynx::Net {
|
|||||||
// Get the number of registered sessions
|
// Get the number of registered sessions
|
||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
|
bool exists(uint32_t sessionID) const;
|
||||||
|
|
||||||
// IP management
|
// IP management
|
||||||
|
|
||||||
// Get the lowest available IPv4 address; Returns 0 if none available
|
// Get the lowest available IPv4 address; Returns 0 if none available
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ namespace ColumnLynx::Net {
|
|||||||
return static_cast<int>(mSessions.size());
|
return static_cast<int>(mSessions.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SessionRegistry::exists(uint32_t sessionID) const {
|
||||||
|
std::shared_lock lock(mMutex);
|
||||||
|
return mSessions.find(sessionID) != mSessions.end();
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t SessionRegistry::getFirstAvailableIP(uint32_t baseIP, uint8_t mask) const {
|
uint32_t SessionRegistry::getFirstAvailableIP(uint32_t baseIP, uint8_t mask) const {
|
||||||
std::shared_lock lock(mMutex);
|
std::shared_lock lock(mMutex);
|
||||||
|
|
||||||
|
|||||||
@@ -211,8 +211,10 @@ namespace ColumnLynx::Net::TCP {
|
|||||||
|
|
||||||
std::memcpy(mConnectionAESKey.data(), decrypted.data(), decrypted.size());
|
std::memcpy(mConnectionAESKey.data(), decrypted.data(), decrypted.size());
|
||||||
|
|
||||||
// Make a Session ID
|
// Make a Session ID - unique and not zero (zero is reserved for invalid sessions)
|
||||||
|
do {
|
||||||
randombytes_buf(&mConnectionSessionID, sizeof(mConnectionSessionID));
|
randombytes_buf(&mConnectionSessionID, sizeof(mConnectionSessionID));
|
||||||
|
} while (SessionRegistry::getInstance().exists(mConnectionSessionID) || mConnectionSessionID == 0); // Regenerate if it already exists or is zero (zero is reserved for invalid sessions)
|
||||||
|
|
||||||
// Encrypt the Session ID with the established AES key (using symmetric encryption, nonce can be all zeros for this purpose)
|
// Encrypt the Session ID with the established AES key (using symmetric encryption, nonce can be all zeros for this purpose)
|
||||||
Nonce symNonce{}; // All zeros
|
Nonce symNonce{}; // All zeros
|
||||||
|
|||||||
Reference in New Issue
Block a user