1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-18 01:42:38 +01:00

Codechange: make network crypto enum classes

This commit is contained in:
Rubidium
2025-02-06 16:30:28 +01:00
committed by rubidium42
parent fef2baf041
commit 8ca03a3766
7 changed files with 47 additions and 47 deletions

View File

@@ -286,7 +286,7 @@ NetworkAuthenticationServerHandler::ResponseResult X25519AuthenticationHandler::
{
if (p.RemainingBytesToTransfer() != X25519_KEY_SIZE + X25519_MAC_SIZE + X25519_KEY_EXCHANGE_MESSAGE_SIZE) {
Debug(net, 1, "[crypto] Received auth response of illegal size; authentication aborted.");
return NetworkAuthenticationServerHandler::NOT_AUTHENTICATED;
return NetworkAuthenticationServerHandler::ResponseResult::NotAuthenticated;
}
X25519KeyExchangeMessage message{};
@@ -299,7 +299,7 @@ NetworkAuthenticationServerHandler::ResponseResult X25519AuthenticationHandler::
if (!this->derived_keys.Exchange(this->peer_public_key, X25519KeyExchangeSide::SERVER,
this->our_secret_key, this->our_public_key, derived_key_extra_payload)) {
Debug(net, 0, "[crypto] Peer sent an illegal public key; authentication aborted.");
return NetworkAuthenticationServerHandler::NOT_AUTHENTICATED;
return NetworkAuthenticationServerHandler::ResponseResult::NotAuthenticated;
}
if (crypto_aead_unlock(message.data(), mac.data(), this->derived_keys.ClientToServer().data(), this->key_exchange_nonce.data(),
@@ -308,20 +308,20 @@ NetworkAuthenticationServerHandler::ResponseResult X25519AuthenticationHandler::
* The ciphertext and the message authentication code do not match with the encryption key.
* This is most likely an invalid password, or possibly a bug in the client.
*/
return NetworkAuthenticationServerHandler::NOT_AUTHENTICATED;
return NetworkAuthenticationServerHandler::ResponseResult::NotAuthenticated;
}
return NetworkAuthenticationServerHandler::AUTHENTICATED;
return NetworkAuthenticationServerHandler::ResponseResult::Authenticated;
}
/* virtual */ NetworkAuthenticationClientHandler::RequestResult X25519PAKEClientHandler::ReceiveRequest(struct Packet &p)
{
bool success = this->X25519AuthenticationHandler::ReceiveRequest(p);
if (!success) return NetworkAuthenticationClientHandler::INVALID;
if (!success) return NetworkAuthenticationClientHandler::RequestResult::Invalid;
this->handler->AskUserForPassword(this->handler);
return NetworkAuthenticationClientHandler::AWAIT_USER_INPUT;
return NetworkAuthenticationClientHandler::RequestResult::AwaitUserInput;
}
/**
@@ -351,10 +351,10 @@ NetworkAuthenticationServerHandler::ResponseResult X25519AuthenticationHandler::
/* virtual */ NetworkAuthenticationServerHandler::ResponseResult X25519AuthorizedKeyServerHandler::ReceiveResponse(Packet &p)
{
ResponseResult result = this->X25519AuthenticationHandler::ReceiveResponse(p, {});
if (result != AUTHENTICATED) return result;
if (result != ResponseResult::Authenticated) return result;
std::string peer_public_key = this->GetPeerPublicKey();
return this->authorized_key_handler->IsAllowed(peer_public_key) ? AUTHENTICATED : NOT_AUTHENTICATED;
return this->authorized_key_handler->IsAllowed(peer_public_key) ? ResponseResult::Authenticated : ResponseResult::NotAuthenticated;
}
@@ -364,7 +364,7 @@ NetworkAuthenticationServerHandler::ResponseResult X25519AuthenticationHandler::
auto is_of_method = [method](Handler &handler) { return handler->GetAuthenticationMethod() == method; };
auto it = std::ranges::find_if(handlers, is_of_method);
if (it == handlers.end()) return INVALID;
if (it == handlers.end()) return RequestResult::Invalid;
this->current_handler = it->get();
@@ -415,10 +415,10 @@ void CombinedAuthenticationServerHandler::Add(CombinedAuthenticationServerHandle
Debug(net, 9, "Receiving {} authentication response", this->GetName());
ResponseResult result = this->handlers.back()->ReceiveResponse(p);
if (result != NOT_AUTHENTICATED) return result;
if (result != ResponseResult::NotAuthenticated) return result;
this->handlers.pop_back();
return this->CanBeUsed() ? RETRY_NEXT_METHOD : NOT_AUTHENTICATED;
return this->CanBeUsed() ? ResponseResult::RetryNextMethod : ResponseResult::NotAuthenticated;
}
/* virtual */ std::string_view CombinedAuthenticationServerHandler::GetName() const