MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ReceiveResponse

Method ReceiveResponse

src/network/network_crypto.cpp:285–315  ·  view source on GitHub ↗

* Read the key exchange data from a \c Packet that came from the client, and check whether the client passes the key * exchange successfully. * @param p The packet that has been received. * @param derived_key_extra_payload The extra payload to pass to the key exchange. * @return Whether the authentication was successful or not. */

Source from the content-addressed store, hash-verified

283 * @return Whether the authentication was successful or not.
284 */
285NetworkAuthenticationServerHandler::ResponseResult X25519AuthenticationHandler::ReceiveResponse(Packet &p, std::string_view derived_key_extra_payload)
286{
287 if (p.RemainingBytesToTransfer() != X25519_KEY_SIZE + X25519_MAC_SIZE + X25519_KEY_EXCHANGE_MESSAGE_SIZE) {
288 Debug(net, 1, "[crypto] Received auth response of illegal size; authentication aborted.");
289 return NetworkAuthenticationServerHandler::ResponseResult::NotAuthenticated;
290 }
291
292 X25519KeyExchangeMessage message{};
293 X25519Mac mac;
294
295 p.Recv_bytes(this->peer_public_key);
296 p.Recv_bytes(mac);
297 p.Recv_bytes(message);
298
299 if (!this->derived_keys.Exchange(this->peer_public_key, X25519KeyExchangeSide::SERVER,
300 this->our_secret_key, this->our_public_key, derived_key_extra_payload)) {
301 Debug(net, 0, "[crypto] Peer sent an illegal public key; authentication aborted.");
302 return NetworkAuthenticationServerHandler::ResponseResult::NotAuthenticated;
303 }
304
305 if (crypto_aead_unlock(message.data(), mac.data(), this->derived_keys.ClientToServer().data(), this->key_exchange_nonce.data(),
306 this->peer_public_key.data(), this->peer_public_key.size(), message.data(), message.size()) != 0) {
307 /*
308 * The ciphertext and the message authentication code do not match with the encryption key.
309 * This is most likely an invalid password, or possibly a bug in the client.
310 */
311 return NetworkAuthenticationServerHandler::ResponseResult::NotAuthenticated;
312 }
313
314 return NetworkAuthenticationServerHandler::ResponseResult::Authenticated;
315}
316
317
318/* virtual */ NetworkAuthenticationClientHandler::RequestResult X25519PAKEClientHandler::ReceiveRequest(struct Packet &p)

Callers 3

TestAuthenticationFunction · 0.45

Calls 12

GetPeerPublicKeyMethod · 0.95
CanBeUsedMethod · 0.95
crypto_aead_unlockFunction · 0.85
Recv_bytesMethod · 0.80
ExchangeMethod · 0.80
ClientToServerMethod · 0.80
IsAllowedMethod · 0.80
pop_backMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
GetNameMethod · 0.45

Tested by 1

TestAuthenticationFunction · 0.36