MCPcopy Create free account
hub / github.com/HumbleNet/HumbleNet / getVerifiedGame

Method getVerifiedGame

src/peer-server/server.cpp:13–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11 }
12
13 Game *Server::getVerifiedGame(const HumblePeer::HelloServer* hello)
14 {
15 GameRecord record;
16 auto gameToken = hello->gameToken();
17 auto gameSignature = hello->gameSignature();
18
19 if (!gameToken || !gameSignature) {
20 LOG_ERROR("No game token provided!\n");
21 return nullptr;
22 }
23
24 if (!m_gameDB->findByToken(gameToken->c_str(), record)) {
25 // Game not found by DB
26 LOG_ERROR("Invalid game token: %s.\n", gameToken->c_str());
27 return nullptr;
28 }
29
30 // Verify signature
31 if (record.verify) {
32 HMACContext hmac;
33 HMACInit(&hmac, (const uint8_t*)record.secret.c_str(), record.secret.size());
34
35 auto authToken = hello->authToken();
36 if (authToken) {
37 HMACInput(&hmac, authToken->Data(), authToken->size());
38 }
39 auto reconnect = hello->authToken();
40 if (reconnect) {
41 HMACInput(&hmac, reconnect->Data(), reconnect->size());
42 }
43
44 auto attributes = hello->attributes();
45
46 if (attributes) {
47 for (const auto& it : *attributes) {
48 auto key = it->key();
49 auto value = it->value();
50 HMACInput(&hmac, key->Data(), key->size());
51 HMACInput(&hmac, value->Data(), value->size());
52 }
53 }
54
55 uint8_t hmacresult[HMAC_DIGEST_SIZE];
56 HMACResult(&hmac, hmacresult);
57 std::string signature;
58 HMACResultToHex(hmacresult, signature);
59
60 if (signature.compare(gameSignature->c_str()) != 0) {
61 LOG_ERROR("Invalid game signature provided for token: %s\n", gameToken->c_str());
62 return nullptr;
63 }
64 }
65
66 auto it = this->games.find(record.game_id);
67 if (it == this->games.end()) {
68 // not found, create
69 Game *g = new Game(record.game_id);
70 this->games.emplace(record.game_id, std::unique_ptr<Game>(g));

Callers 1

processMsgMethod · 0.80

Calls 12

HMACInitFunction · 0.85
HMACInputFunction · 0.85
HMACResultFunction · 0.85
HMACResultToHexFunction · 0.85
findByTokenMethod · 0.80
c_strMethod · 0.80
findMethod · 0.80
sizeMethod · 0.45
DataMethod · 0.45
compareMethod · 0.45
endMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected