This commit is contained in:
malloc 2018-06-28 19:07:28 -05:00
commit 44a465810b
7 changed files with 27 additions and 29 deletions

View file

@ -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;

View file

@ -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);
= key.GetPrivateKey().ToRawString((uint64_t)key.key_size_bytes);
this->state = std::string(256, 0);
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];
}

View file

@ -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];
};
}}

View file

@ -106,6 +106,7 @@ bool sosc::MasterIntra::InitAttempt(sosc::Packet& pck) {
return this->Close(
Packet(kEncryptionError, { net::htonv<uint16_t>(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;

View file

@ -49,7 +49,7 @@ private:
class Stack {
public:
Stack(Pool<T>* pool);
explicit Stack(Pool<T>* pool);
Stack(const Stack&) = delete;
void Start();

View file

@ -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 "::";

View file

@ -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;