diff --git a/server/src/crypto/bfish.hpp b/server/src/crypto/bfish.hpp index 68842d8..7747258 100644 --- a/server/src/crypto/bfish.hpp +++ b/server/src/crypto/bfish.hpp @@ -9,7 +9,7 @@ namespace sosc { namespace cgc { class Blowfish { public: - Blowfish(const std::string& key); + explicit Blowfish(const std::string& key); std::string Encrypt(std::string data) const; std::string Decrypt(std::string data) const; diff --git a/server/src/crypto/cipher.cpp b/server/src/crypto/cipher.cpp index 3d85299..a6ab929 100644 --- a/server/src/crypto/cipher.cpp +++ b/server/src/crypto/cipher.cpp @@ -9,11 +9,10 @@ static void _swap(T& a, T& b) { sosc::cgc::Cipher::Cipher(const KeyExchange& key) { std::string key_raw - = key.GetPrivateKey().ToRawString(key.key_size_bytes); - - this->state = std::string(256, 0); + = key.GetPrivateKey().ToRawString((uint64_t)key.key_size_bytes); + for(int i = 0; i < this->state_size; ++i) - this->state[i] = i; + this->state[i] = (uint8_t)i; int i = 0, j = 0; for(i = 0; i < this->state_size; ++i) @@ -22,9 +21,11 @@ sosc::cgc::Cipher::Cipher(const KeyExchange& key) { GenerateStream(1024); } -void sosc::cgc::Cipher::Parse(std::string* data) { - std::string stream = this->GenerateStream(data->length()); - for(std::string::size_type i = 0; i < data->length(); ++i) +void sosc::cgc::Cipher::Parse + (std::string* data, std::string::size_type offset) +{ + std::string stream = this->GenerateStream(data->length() - offset); + for(std::string::size_type i = offset; i < data->length(); ++i) (*data)[i] ^= stream[i]; } diff --git a/server/src/crypto/cipher.hpp b/server/src/crypto/cipher.hpp index 5fedff9..aa0b8c2 100644 --- a/server/src/crypto/cipher.hpp +++ b/server/src/crypto/cipher.hpp @@ -8,15 +8,15 @@ namespace sosc { namespace cgc { class Cipher { public: - Cipher() {}; - Cipher(const KeyExchange& key); + Cipher() = default; + explicit Cipher(const KeyExchange& key); - void Parse(std::string* data); + void Parse(std::string* data, std::string::size_type offset = 0); private: std::string GenerateStream(uint64_t length); const int state_size = 256; - std::string state; + uint8_t state[state_size]; }; }} diff --git a/server/src/hosts/master_intra.cpp b/server/src/hosts/master_intra.cpp index cc372f4..655329d 100644 --- a/server/src/hosts/master_intra.cpp +++ b/server/src/hosts/master_intra.cpp @@ -106,6 +106,7 @@ bool sosc::MasterIntra::InitAttempt(sosc::Packet &pck) { return this->Close( Packet(kEncryptionError, { net::htonv(0x101) })); + this->sock.Send(response); } @@ -150,6 +151,7 @@ bool sosc::MasterIntra::Authentication(sosc::Packet &pck) { _ctx.license_check_mtx.unlock(); + this->sock.Send(Packet(kPositiveAck, { packetId })); this->license = pck[2]; this->authed = true; return true; diff --git a/server/src/sock/pool.hpp b/server/src/sock/pool.hpp index fb8c756..fa9aaf8 100644 --- a/server/src/sock/pool.hpp +++ b/server/src/sock/pool.hpp @@ -49,7 +49,7 @@ private: class Stack { public: - Stack(Pool* pool); + explicit Stack(Pool* pool); Stack(const Stack&) = delete; void Start(); diff --git a/server/src/utils/net.cpp b/server/src/utils/net.cpp index 9845582..bb71280 100644 --- a/server/src/utils/net.cpp +++ b/server/src/utils/net.cpp @@ -88,7 +88,7 @@ int sosc::net::IpAddress::ParseIPv6Part addrpart_t* ptr = &(this->parts[from_start ? i : 8 - parts.size() + i]); std::string part = str::trim(parts[i]); - int part_len = part.length(); + auto part_len = (int)part.length(); if(part_len > 4 || part_len == 0) return -1; @@ -98,32 +98,28 @@ int sosc::net::IpAddress::ParseIPv6Part continue; } - for(int i = 0; i < part_len; ++i) { - if(part[i] == '*') { - part[i] = '0'; - ptr->second |= 1 << (part_len - i - 1); - } else if(!(part[i] >= 'a' && part[i] <= 'f') - && !(part[i] >= 'A' && part[i] <= 'F') - && !(part[i] >= '0' && part[i] <= '9')) + for(int j = 0; j < part_len; ++j) { + if(part[j] == '*') { + part[j] = '0'; + ptr->second |= 1 << (part_len - j - 1); + } else if(!(part[j] >= 'a' && part[j] <= 'f') + && !(part[j] >= 'A' && part[j] <= 'F') + && !(part[j] >= '0' && part[j] <= '9')) { return -1; } } - ptr->first = std::stoi(part, NULL, 16); + ptr->first = (uint16_t)std::stoi(part, nullptr, 16); } - return parts.size(); + return (int)parts.size(); } sosc::net::IpAddress::operator std::string () const { return this->ToString(); } -sosc::net::IpAddress::operator const char* () const { - return this->ToString().c_str(); -} - std::string sosc::net::IpAddress::ToString(bool force_ipv6) const { // TODO THIS return "::"; diff --git a/server/src/utils/net.hpp b/server/src/utils/net.hpp index 14ffb8b..1f6730c 100644 --- a/server/src/utils/net.hpp +++ b/server/src/utils/net.hpp @@ -56,7 +56,6 @@ public: bool Parse(const std::string& addr); operator std::string () const; - operator const char* () const; std::string ToString(bool force_ipv6 = false) const; bool operator == (const IpAddress& rhs) const; @@ -112,7 +111,7 @@ T ntohv(std::string net_var, size_t offset = 0) { int i = is_big_endian() ? b : byte_count - b - 1; - ((uint8_t*)&host_var)[i] = net_var[offset + b]; + ((uint8_t*)&host_var)[i] = (uint8_t)net_var[offset + b]; } return host_var;