MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / Client_Handle_TOKEN

Method Client_Handle_TOKEN

src/openrct2/network/NetworkBase.cpp:2282–2328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2280 }
2281
2282 void NetworkBase::Client_Handle_TOKEN(Connection& connection, Packet& packet)
2283 {
2284 auto keyPath = GetPrivateKeyPath(Config::Get().network.playerName);
2285 if (!File::Exists(keyPath))
2286 {
2287 LOG_ERROR("Key file (%s) was not found. Restart client to re-generate it.", keyPath.c_str());
2288 return;
2289 }
2290
2291 try
2292 {
2293 auto fs = FileStream(keyPath, FileMode::open);
2294 if (!_key.LoadPrivate(&fs))
2295 {
2296 throw std::runtime_error("Failed to load private key.");
2297 }
2298 }
2299 catch (const std::exception&)
2300 {
2301 LOG_ERROR("Failed to load key %s", keyPath.c_str());
2302 connection.setLastDisconnectReason(STR_MULTIPLAYER_VERIFICATION_FAILURE);
2303 connection.disconnect();
2304 return;
2305 }
2306
2307 uint32_t challenge_size;
2308 packet >> challenge_size;
2309 const char* challenge = reinterpret_cast<const char*>(packet.read(challenge_size));
2310
2311 std::vector<uint8_t> signature;
2312 const std::string pubkey = _key.PublicKeyString();
2313 _challenge.resize(challenge_size);
2314 std::memcpy(_challenge.data(), challenge, challenge_size);
2315 bool ok = _key.Sign(_challenge.data(), _challenge.size(), signature);
2316 if (!ok)
2317 {
2318 LOG_ERROR("Failed to sign server's challenge.");
2319 connection.setLastDisconnectReason(STR_MULTIPLAYER_VERIFICATION_FAILURE);
2320 connection.disconnect();
2321 return;
2322 }
2323 // Don't keep private key in memory. There's no need and it may get leaked
2324 // when process dump gets collected at some point in future.
2325 _key.Unload();
2326
2327 Client_Send_AUTH(Config::Get().network.playerName, gCustomPassword, pubkey, signature);
2328 }
2329
2330 void NetworkBase::ServerHandleRequestGamestate(Connection& connection, Packet& packet)
2331 {

Callers

nothing calls this directly

Calls 12

GetPrivateKeyPathFunction · 0.85
ExistsFunction · 0.85
FileStreamClass · 0.85
LoadPrivateMethod · 0.80
disconnectMethod · 0.80
PublicKeyStringMethod · 0.80
SignMethod · 0.80
readMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
UnloadMethod · 0.45

Tested by

no test coverage detected