OpenTTD Source: X25519AuthorizedKeyClientHandler Class Reference

OpenTTD Source 15.3

Public Member Functions | Static Public Member Functions
X25519AuthorizedKeyClientHandler Class Reference

Handler for clients using a X25519 key exchange to perform authentication via a set of authorized (public) keys of clients. More...

`#include <network_crypto_internal.h>`

Inheritance diagram for X25519AuthorizedKeyClientHandler:

## Public Member Functions
| X25519AuthorizedKeyClientHandler (const X25519SecretKey &secret_key)
| Create the handler that uses the given password to check against.
virtual RequestResult | ReceiveRequest (struct Packet &p) override
| Read a request from the server.
virtual bool | SendResponse (struct Packet &p) override
| Create the response to send to the server.
virtual std::string_view | GetName () const override
| Get the name of the handler for debug messages.
virtual NetworkAuthenticationMethod | GetAuthenticationMethod () const override
| Get the method this handler is providing functionality for.
virtual bool | ReceiveEnableEncryption (struct Packet &p) override
| Read the request to enable encryption from the server.
virtual std::unique_ptr< NetworkEncryptionHandler > | CreateClientToServerEncryptionHandler () const override
| Create a NetworkEncryptionHandler to encrypt or decrypt messages from the client to the server.
virtual std::unique_ptr< NetworkEncryptionHandler > | CreateServerToClientEncryptionHandler () const override
| Create a NetworkEncryptionHandler to encrypt or decrypt messages from the server to the client.

## Static Public Member Functions
static X25519SecretKey | GetValidSecretKeyAndUpdatePublicKey (std::string &secret_key, std::string &public_key)
| Get the secret key from the given string.
Static Public Member Functions inherited from NetworkAuthenticationClientHandler
static void | EnsureValidSecretKeyAndUpdatePublicKey (std::string &secret_key, std::string &public_key)
| Ensures that the given secret key is valid, and when not overwrite it with a valid secret key.
static std::unique_ptr< NetworkAuthenticationClientHandler > | Create (std::shared_ptr< NetworkAuthenticationPasswordRequestHandler > password_handler, std::string &secret_key, std::string &public_key)
| Create a NetworkAuthenticationClientHandler.

## Additional Inherited Members
Public Types inherited from NetworkAuthenticationClientHandler
enum class | RequestResult : uint8_t { AwaitUserInput , ReadyForResponse , Invalid }
| The processing result of receiving a request. More...
Protected Types inherited from NetworkAuthenticationClientHandler
enum class | RequestResult : uint8_t { AwaitUserInput , ReadyForResponse , Invalid }
| The processing result of receiving a request. More...
Protected Member Functions inherited from X25519AuthenticationHandler
| X25519AuthenticationHandler (const X25519SecretKey &secret_key)
| Create the handler, and generate the public keys accordingly.
void | SendRequest (struct Packet &p)
bool | ReceiveRequest (struct Packet &p)
| Read the key exchange data from a `Packet` that came from the server,.
bool | SendResponse (struct Packet &p, std::string_view derived_key_extra_payload)
| Perform the key exchange, and when that is correct fill the `Packet` with the appropriate data.
NetworkAuthenticationServerHandler::ResponseResult | ReceiveResponse (struct Packet &p, std::string_view derived_key_extra_payload)
| Read the key exchange data from a `Packet` that came from the client, and check whether the client passes the key exchange successfully.
std::string | GetPeerPublicKey () const
| Get the public key the peer provided for the key exchange.
void | SendEnableEncryption (struct Packet &p) const
| Send the initial nonce for the encrypted connection.
bool | ReceiveEnableEncryption (struct Packet &p)
| Receive the initial nonce for the encrypted connection.
std::unique_ptr< NetworkEncryptionHandler > | CreateClientToServerEncryptionHandler () const
std::unique_ptr< NetworkEncryptionHandler > | CreateServerToClientEncryptionHandler () const
Static Protected Member Functions inherited from NetworkAuthenticationClientHandler
static void | EnsureValidSecretKeyAndUpdatePublicKey (std::string &secret_key, std::string &public_key)
| Ensures that the given secret key is valid, and when not overwrite it with a valid secret key.
static std::unique_ptr< NetworkAuthenticationClientHandler > | Create (std::shared_ptr< NetworkAuthenticationPasswordRequestHandler > password_handler, std::string &secret_key, std::string &public_key)
| Create a NetworkAuthenticationClientHandler.

## Detailed Description

Handler for clients using a X25519 key exchange to perform authentication via a set of authorized (public) keys of clients.

This follows the method described in `X25519AuthenticationHandler`. Once all these checks have succeeded, it will check whether the public key of the client is in the list of authorized keys to login.

Definition at line 244 of file network_crypto_internal.h.

## Constructor & Destructor Documentation

## ◆ X25519AuthorizedKeyClientHandler()

X25519AuthorizedKeyClientHandler::X25519AuthorizedKeyClientHandler | ( | const X25519SecretKey & | secret_key | ) |
| inline

Create the handler that uses the given password to check against.

Parameters

  secret_key | The secret key to initialize this handler with.

Definition at line 250 of file network_crypto_internal.h.

## Member Function Documentation

## ◆ CreateClientToServerEncryptionHandler()

virtual std::unique_ptr< NetworkEncryptionHandler > X25519AuthorizedKeyClientHandler::CreateClientToServerEncryptionHandler | ( |  | ) | const
| inlineoverridevirtual

Create a NetworkEncryptionHandler to encrypt or decrypt messages from the client to the server.

Returns
  The handler for the client to server encryption.

Implements NetworkAuthenticationHandler.

Definition at line 259 of file network_crypto_internal.h.

## ◆ CreateServerToClientEncryptionHandler()

virtual std::unique_ptr< NetworkEncryptionHandler > X25519AuthorizedKeyClientHandler::CreateServerToClientEncryptionHandler | ( |  | ) | const
| inlineoverridevirtual

Create a NetworkEncryptionHandler to encrypt or decrypt messages from the server to the client.

Returns
  The handler for the server to client encryption.

Implements NetworkAuthenticationHandler.

Definition at line 260 of file network_crypto_internal.h.

## ◆ GetAuthenticationMethod()

virtual NetworkAuthenticationMethod X25519AuthorizedKeyClientHandler::GetAuthenticationMethod | ( |  | ) | const
| inlineoverridevirtual

Get the method this handler is providing functionality for.

Returns
  The `NetworkAuthenticationMethod`.

Implements NetworkAuthenticationHandler.

Definition at line 256 of file network_crypto_internal.h.

References X25519_AuthorizedKey.

## ◆ GetName()

virtual std::string_view X25519AuthorizedKeyClientHandler::GetName | ( |  | ) | const
| inlineoverridevirtual

Get the name of the handler for debug messages.

Returns
  The name of the handler.

Implements NetworkAuthenticationHandler.

Definition at line 255 of file network_crypto_internal.h.

## ◆ GetValidSecretKeyAndUpdatePublicKey()

X25519SecretKey X25519AuthorizedKeyClientHandler::GetValidSecretKeyAndUpdatePublicKey | ( | std::string & | secret_key,
|  | std::string & | public_key
| ) |  |
| static

Get the secret key from the given string.

If that is not a valid secret key, reset it with a random one. Furthermore update the public key so it is always in sync with the private key.

Parameters

  secret_key | The secret key to read/validate/fix.
  public_key | The public key to update.

Returns
  The valid secret key.

Definition at line 334 of file network_crypto.cpp.

References ConvertHexToBytes(), X25519SecretKey::CreateRandom(), Debug, and FormatArrayAsHex().

Referenced by NetworkAuthenticationClientHandler::Create(), and NetworkAuthenticationClientHandler::EnsureValidSecretKeyAndUpdatePublicKey().

## ◆ ReceiveEnableEncryption()

virtual bool X25519AuthorizedKeyClientHandler::ReceiveEnableEncryption | ( | struct Packet & | p | ) |
| inlineoverridevirtual

Read the request to enable encryption from the server.

Parameters

  p | The request from the server.

Implements NetworkAuthenticationClientHandler.

Definition at line 258 of file network_crypto_internal.h.

References X25519AuthenticationHandler::ReceiveEnableEncryption().

## ◆ ReceiveRequest()

virtual RequestResult X25519AuthorizedKeyClientHandler::ReceiveRequest | ( | struct Packet & | p | ) |
| inlineoverridevirtual

Read a request from the server.

Parameters

  p | The packet to read the request from.

Returns
  True when valid, otherwise false.

Implements NetworkAuthenticationClientHandler.

Definition at line 252 of file network_crypto_internal.h.

References NetworkAuthenticationClientHandler::Invalid, NetworkAuthenticationClientHandler::ReadyForResponse, and X25519AuthenticationHandler::ReceiveRequest().

## ◆ SendResponse()

virtual bool X25519AuthorizedKeyClientHandler::SendResponse | ( | struct Packet & | p | ) |
| inlineoverridevirtual

Create the response to send to the server.

Parameters

  p | The packet to write the response from.

Returns
  True when a valid packet was made, otherwise false.

Implements NetworkAuthenticationClientHandler.

Definition at line 253 of file network_crypto_internal.h.

References X25519AuthenticationHandler::SendResponse().

The documentation for this class was generated from the following files:

- src/network/network_crypto_internal.h
- src/network/network_crypto.cpp