Merge branch 'master' of https://github.com/MallocNull/sockscape
This commit is contained in:
commit
44a465810b
7 changed files with 27 additions and 29 deletions
|
@ -9,7 +9,7 @@ namespace sosc {
|
||||||
namespace cgc {
|
namespace cgc {
|
||||||
class Blowfish {
|
class Blowfish {
|
||||||
public:
|
public:
|
||||||
Blowfish(const std::string& key);
|
explicit Blowfish(const std::string& key);
|
||||||
|
|
||||||
std::string Encrypt(std::string data) const;
|
std::string Encrypt(std::string data) const;
|
||||||
std::string Decrypt(std::string data) const;
|
std::string Decrypt(std::string data) const;
|
||||||
|
|
|
@ -9,11 +9,10 @@ static void _swap(T& a, T& b) {
|
||||||
|
|
||||||
sosc::cgc::Cipher::Cipher(const KeyExchange& key) {
|
sosc::cgc::Cipher::Cipher(const KeyExchange& key) {
|
||||||
std::string key_raw
|
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)
|
for(int i = 0; i < this->state_size; ++i)
|
||||||
this->state[i] = i;
|
this->state[i] = (uint8_t)i;
|
||||||
|
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
for(i = 0; i < this->state_size; ++i)
|
for(i = 0; i < this->state_size; ++i)
|
||||||
|
@ -22,9 +21,11 @@ sosc::cgc::Cipher::Cipher(const KeyExchange& key) {
|
||||||
GenerateStream(1024);
|
GenerateStream(1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sosc::cgc::Cipher::Parse(std::string* data) {
|
void sosc::cgc::Cipher::Parse
|
||||||
std::string stream = this->GenerateStream(data->length());
|
(std::string* data, std::string::size_type offset)
|
||||||
for(std::string::size_type i = 0; i < data->length(); ++i)
|
{
|
||||||
|
std::string stream = this->GenerateStream(data->length() - offset);
|
||||||
|
for(std::string::size_type i = offset; i < data->length(); ++i)
|
||||||
(*data)[i] ^= stream[i];
|
(*data)[i] ^= stream[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,15 @@ namespace sosc {
|
||||||
namespace cgc {
|
namespace cgc {
|
||||||
class Cipher {
|
class Cipher {
|
||||||
public:
|
public:
|
||||||
Cipher() {};
|
Cipher() = default;
|
||||||
Cipher(const KeyExchange& key);
|
explicit Cipher(const KeyExchange& key);
|
||||||
|
|
||||||
void Parse(std::string* data);
|
void Parse(std::string* data, std::string::size_type offset = 0);
|
||||||
private:
|
private:
|
||||||
std::string GenerateStream(uint64_t length);
|
std::string GenerateStream(uint64_t length);
|
||||||
|
|
||||||
const int state_size = 256;
|
const int state_size = 256;
|
||||||
std::string state;
|
uint8_t state[state_size];
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,7 @@ bool sosc::MasterIntra::InitAttempt(sosc::Packet& pck) {
|
||||||
return this->Close(
|
return this->Close(
|
||||||
Packet(kEncryptionError, { net::htonv<uint16_t>(0x101) }));
|
Packet(kEncryptionError, { net::htonv<uint16_t>(0x101) }));
|
||||||
|
|
||||||
|
|
||||||
this->sock.Send(response);
|
this->sock.Send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +151,7 @@ bool sosc::MasterIntra::Authentication(sosc::Packet& pck) {
|
||||||
|
|
||||||
_ctx.license_check_mtx.unlock();
|
_ctx.license_check_mtx.unlock();
|
||||||
|
|
||||||
|
this->sock.Send(Packet(kPositiveAck, { packetId }));
|
||||||
this->license = pck[2];
|
this->license = pck[2];
|
||||||
this->authed = true;
|
this->authed = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -49,7 +49,7 @@ private:
|
||||||
|
|
||||||
class Stack {
|
class Stack {
|
||||||
public:
|
public:
|
||||||
Stack(Pool<T>* pool);
|
explicit Stack(Pool<T>* pool);
|
||||||
Stack(const Stack&) = delete;
|
Stack(const Stack&) = delete;
|
||||||
|
|
||||||
void Start();
|
void Start();
|
||||||
|
|
|
@ -88,7 +88,7 @@ int sosc::net::IpAddress::ParseIPv6Part
|
||||||
addrpart_t* ptr =
|
addrpart_t* ptr =
|
||||||
&(this->parts[from_start ? i : 8 - parts.size() + i]);
|
&(this->parts[from_start ? i : 8 - parts.size() + i]);
|
||||||
std::string part = str::trim(parts[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)
|
if(part_len > 4 || part_len == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -98,32 +98,28 @@ int sosc::net::IpAddress::ParseIPv6Part
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < part_len; ++i) {
|
for(int j = 0; j < part_len; ++j) {
|
||||||
if(part[i] == '*') {
|
if(part[j] == '*') {
|
||||||
part[i] = '0';
|
part[j] = '0';
|
||||||
ptr->second |= 1 << (part_len - i - 1);
|
ptr->second |= 1 << (part_len - j - 1);
|
||||||
} else if(!(part[i] >= 'a' && part[i] <= 'f')
|
} else if(!(part[j] >= 'a' && part[j] <= 'f')
|
||||||
&& !(part[i] >= 'A' && part[i] <= 'F')
|
&& !(part[j] >= 'A' && part[j] <= 'F')
|
||||||
&& !(part[i] >= '0' && part[i] <= '9'))
|
&& !(part[j] >= '0' && part[j] <= '9'))
|
||||||
{
|
{
|
||||||
return -1;
|
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 {
|
sosc::net::IpAddress::operator std::string () const {
|
||||||
return this->ToString();
|
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 {
|
std::string sosc::net::IpAddress::ToString(bool force_ipv6) const {
|
||||||
// TODO THIS
|
// TODO THIS
|
||||||
return "::";
|
return "::";
|
||||||
|
|
|
@ -56,7 +56,6 @@ public:
|
||||||
bool Parse(const std::string& addr);
|
bool Parse(const std::string& addr);
|
||||||
|
|
||||||
operator std::string () const;
|
operator std::string () const;
|
||||||
operator const char* () const;
|
|
||||||
std::string ToString(bool force_ipv6 = false) const;
|
std::string ToString(bool force_ipv6 = false) const;
|
||||||
|
|
||||||
bool operator == (const IpAddress& rhs) 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()
|
int i = is_big_endian()
|
||||||
? b : byte_count - b - 1;
|
? 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;
|
return host_var;
|
||||||
|
|
Loading…
Reference in a new issue