This commit is contained in:
malloc 2018-05-11 16:05:21 -05:00
parent 867d8a3fcc
commit 4d1894066c
4 changed files with 35 additions and 7 deletions

View file

@ -102,8 +102,8 @@ Communication between the master server and clients will be done over a WebSocke
</thead> </thead>
<tr> <tr>
<td>1</td> <td>1</td>
<td>Error Message</td> <td>Error Code</td>
<td>String</td> <td>Packed Unsigned Short</td>
</tr> </tr>
</table> </table>
@ -145,8 +145,8 @@ Communication between the master server and clients will be done over a WebSocke
</tr> </tr>
<tr> <tr>
<td>2</td> <td>2</td>
<td>Error Message</td> <td>Error Code</td>
<td>String</td> <td>Packed Unsigned Short</td>
</tr> </tr>
</table> </table>
@ -466,11 +466,16 @@ TODO: MAKE THIS SECTION NOT LOOK LIKE SHIT
### Master / Slave ### Master / Slave
#### S -> M (ID 1) #### M -> S (ID 2)
0x01: KEY SIZE WAS INCORRECT 0x01: KEY SIZE WAS INCORRECT
0x02: COULD NOT PARSE KEY 0x02: COULD NOT PARSE KEY
#### M -> S (ID 4)
0x01: LICENSE DATA INCORRECT
0x02: LICENSE LIMIT REACHED
### Master / Client ### Master / Client
### Slave / Client ### Slave / Client

View file

@ -24,8 +24,8 @@ const std::vector<const char*> _hard_db_sql = {
/** START MIGRATION 0 **/ /** START MIGRATION 0 **/
"CREATE TABLE `SERVER_LICENSES` (" "CREATE TABLE `SERVER_LICENSES` ("
"`KEY_ID` TEXT NOT NULL UNIQUE," "`KEY_ID` TEXT NOT NULL UNIQUE,"
"`SECRET` TEXT NOT NULL UNIQUE," "`SECRET` BLOB NOT NULL UNIQUE,"
"`ALLOWANCE` INTEGER NOT NULL" "`ALLOWANCE` INTEGER NOT NULL DEFAULT 0"
");\n" ");\n"
"CREATE TABLE `USERS` (" "CREATE TABLE `USERS` ("

View file

@ -8,6 +8,8 @@
#include "../crypto/keyex.hpp" #include "../crypto/keyex.hpp"
#include "../crypto/cipher.hpp" #include "../crypto/cipher.hpp"
#include "../db/database.hpp"
namespace sosc { namespace sosc {
/** MASTER -> CLIENT **/ /** MASTER -> CLIENT **/
@ -59,6 +61,11 @@ private:
IntraClient sock; IntraClient sock;
cgc::KeyExchange key; cgc::KeyExchange key;
cgc::Cipher cipher; cgc::Cipher cipher;
bool authed;
int auth_attempts;
const int MAX_AUTH_ATTEMPTS = 3;
std::string license;
}; };
class MasterIntraPool : public Pool<MasterIntra> { class MasterIntraPool : public Pool<MasterIntra> {

View file

@ -1,7 +1,10 @@
#include "master.hpp" #include "master.hpp"
#include "../db/database.hpp"
sosc::MasterIntra::MasterIntra(const IntraClient& client) { sosc::MasterIntra::MasterIntra(const IntraClient& client) {
this->sock = client; this->sock = client;
this->authed = false;
this->auth_attempts = 0;
} }
bool sosc::MasterIntra::Process() { bool sosc::MasterIntra::Process() {
@ -36,7 +39,20 @@ bool sosc::MasterIntra::InitAttempt(sosc::Packet &pck) {
} }
bool sosc::MasterIntra::Authentication(sosc::Packet &pck) { bool sosc::MasterIntra::Authentication(sosc::Packet &pck) {
if(this->authed)
return true;
if(!pck.Check(2, PCK_ANY, 512))
return this->Close(Packet(kNegativeAck, { "\x01" }));
db::Query = db::Query::ScalarInt32(
"SELECT COUNT(*) FROM SERVER_LICENSES "
"WHERE KEY_ID = ? AND SECRET = ?"
);
if(isValid > 0) {
}
} }
bool sosc::MasterIntra::StatusUpdate(sosc::Packet &pck) { bool sosc::MasterIntra::StatusUpdate(sosc::Packet &pck) {