oingo boingo

This commit is contained in:
malloc 2018-05-09 18:11:06 -05:00
parent 9f2821b84f
commit 2e43dfaab8
4 changed files with 17 additions and 13 deletions

View file

@ -39,6 +39,8 @@ public:
bool Close(); bool Close();
bool Close(const Packet& message); bool Close(const Packet& message);
private: private:
bool InitAttempt(Packet& pck);
enum kSlaveToMasterId { enum kSlaveToMasterId {
InitAttempt = 1, InitAttempt = 1,
Authentication, Authentication,

View file

@ -14,15 +14,7 @@ bool sosc::MasterIntra::Process() {
switch(pck.GetId()) { switch(pck.GetId()) {
case InitAttempt: case InitAttempt:
if(!pck.Check(1, key.key_size_bytes)) return this->InitAttempt(pck);
return this->Close(Packet(EncryptionError, { "\x01" }));
Packet response;
if(!this->key.ParseRequest(pck, &response, KeyExchange))
return this->Close(Packet(EncryptionError, { "\x02" }));
this->sock.Send(response);
break;
case Authentication: case Authentication:
break; break;
@ -30,13 +22,23 @@ bool sosc::MasterIntra::Process() {
break; break;
default: default:
this->Close(); return this->Close();
return false;
} }
return true; return true;
} }
bool sosc::MasterIntra::InitAttempt(sosc::Packet &pck) {
if(!pck.Check(1, key.key_size_bytes))
return this->Close(Packet(EncryptionError, { "\x01" }));
Packet response;
if(!this->key.ParseRequest(pck, &response, KeyExchange))
return this->Close(Packet(EncryptionError, { "\x02" }));
this->sock.Send(response);
}
bool sosc::MasterIntra::Close() { bool sosc::MasterIntra::Close() {
this->sock.Close(); this->sock.Close();
return false; return false;

View file

@ -127,7 +127,7 @@ int sosc::Packet::Parse(const std::string& data, std::string* extra) {
return PCK_OK; return PCK_OK;
} }
bool sosc::Packet::Check(int region_count, ...) { bool sosc::Packet::Check(int region_count, ...) const {
if(region_count > 0xFF) if(region_count > 0xFF)
return false; return false;

View file

@ -34,7 +34,7 @@ public:
} }
int Parse(const std::string& data, std::string* extra = nullptr); int Parse(const std::string& data, std::string* extra = nullptr);
bool Check(int region_count, ...); bool Check(int region_count, ...) const;
inline void SetId(uint8_t id) { inline void SetId(uint8_t id) {
this->id = id; this->id = id;