OpenTTD Source  20241121-master-g67a0fccfad
X25519PAKEClientHandler Class Reference

Client side handler for using X25519 with a password-authenticated key exchange. More...

#include <network_crypto_internal.h>

Inheritance diagram for X25519PAKEClientHandler:
X25519AuthenticationHandler NetworkAuthenticationClientHandler NetworkAuthenticationHandler

Public Member Functions

 X25519PAKEClientHandler (const X25519SecretKey &secret_key, std::shared_ptr< NetworkAuthenticationPasswordRequestHandler > handler)
 Create the handler with the given password handler. More...
 
virtual RequestResult ReceiveRequest (struct Packet &p) override
 Read a request from the server. More...
 
virtual bool SendResponse (struct Packet &p) override
 Create the response to send to the server. More...
 
virtual std::string_view GetName () const override
 Get the name of the handler for debug messages. More...
 
virtual NetworkAuthenticationMethod GetAuthenticationMethod () const override
 Get the method this handler is providing functionality for. More...
 
virtual bool ReceiveEnableEncryption (struct Packet &p) override
 Read the request to enable encryption from the server. More...
 
virtual std::unique_ptr< NetworkEncryptionHandlerCreateClientToServerEncryptionHandler () const override
 Create a NetworkEncryptionHandler to encrypt or decrypt messages from the client to the server. More...
 
virtual std::unique_ptr< NetworkEncryptionHandlerCreateServerToClientEncryptionHandler () const override
 Create a NetworkEncryptionHandler to encrypt or decrypt messages from the server to the client. More...
 

Private Attributes

std::shared_ptr< NetworkAuthenticationPasswordRequestHandlerhandler
 

Additional Inherited Members

- Public Types inherited from NetworkAuthenticationClientHandler
enum  RequestResult { AWAIT_USER_INPUT , READY_FOR_RESPONSE , INVALID }
 The processing result of receiving a request. More...
 
- 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. More...
 
static std::unique_ptr< NetworkAuthenticationClientHandlerCreate (std::shared_ptr< NetworkAuthenticationPasswordRequestHandler > password_handler, std::string &secret_key, std::string &public_key)
 Create a NetworkAuthenticationClientHandler. More...
 
- Protected Types inherited from NetworkAuthenticationClientHandler
enum  RequestResult { AWAIT_USER_INPUT , READY_FOR_RESPONSE , 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. More...
 
void SendRequest (struct Packet &p)
 
bool ReceiveRequest (struct Packet &p)
 Read the key exchange data from a Packet that came from the server,. More...
 
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. More...
 
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. More...
 
std::string GetPeerPublicKey () const
 Get the public key the peer provided for the key exchange. More...
 
void SendEnableEncryption (struct Packet &p) const
 Send the initial nonce for the encrypted connection. More...
 
bool ReceiveEnableEncryption (struct Packet &p)
 Receive the initial nonce for the encrypted connection. More...
 
std::unique_ptr< NetworkEncryptionHandlerCreateClientToServerEncryptionHandler () const
 
std::unique_ptr< NetworkEncryptionHandlerCreateServerToClientEncryptionHandler () 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. More...
 
static std::unique_ptr< NetworkAuthenticationClientHandlerCreate (std::shared_ptr< NetworkAuthenticationPasswordRequestHandler > password_handler, std::string &secret_key, std::string &public_key)
 Create a NetworkAuthenticationClientHandler. More...
 

Detailed Description

Client side handler for using X25519 with a password-authenticated key exchange.

This follows the method described in X25519AuthenticationHandler, were the password is the extra payload.

Definition at line 185 of file network_crypto_internal.h.

Constructor & Destructor Documentation

◆ X25519PAKEClientHandler()

X25519PAKEClientHandler::X25519PAKEClientHandler ( const X25519SecretKey secret_key,
std::shared_ptr< NetworkAuthenticationPasswordRequestHandler handler 
)
inline

Create the handler with the given password handler.

Parameters
secret_keyThe secret key to initialize this handler with.
handlerThe handler requesting the password from the user, if required.

Definition at line 195 of file network_crypto_internal.h.

Member Function Documentation

◆ CreateClientToServerEncryptionHandler()

virtual std::unique_ptr<NetworkEncryptionHandler> X25519PAKEClientHandler::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 204 of file network_crypto_internal.h.

◆ CreateServerToClientEncryptionHandler()

virtual std::unique_ptr<NetworkEncryptionHandler> X25519PAKEClientHandler::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 205 of file network_crypto_internal.h.

◆ GetAuthenticationMethod()

virtual NetworkAuthenticationMethod X25519PAKEClientHandler::GetAuthenticationMethod ( ) const
inlineoverridevirtual

Get the method this handler is providing functionality for.

Returns
The NetworkAuthenticationMethod.

Implements NetworkAuthenticationHandler.

Definition at line 201 of file network_crypto_internal.h.

References NETWORK_AUTH_METHOD_X25519_PAKE.

◆ GetName()

virtual std::string_view X25519PAKEClientHandler::GetName ( ) const
inlineoverridevirtual

Get the name of the handler for debug messages.

Returns
The name of the handler.

Implements NetworkAuthenticationHandler.

Definition at line 200 of file network_crypto_internal.h.

◆ ReceiveEnableEncryption()

virtual bool X25519PAKEClientHandler::ReceiveEnableEncryption ( struct Packet p)
inlineoverridevirtual

Read the request to enable encryption from the server.

Parameters
pThe request from the server.

Implements NetworkAuthenticationClientHandler.

Definition at line 203 of file network_crypto_internal.h.

References X25519AuthenticationHandler::ReceiveEnableEncryption().

◆ ReceiveRequest()

NetworkAuthenticationClientHandler::RequestResult X25519PAKEClientHandler::ReceiveRequest ( struct Packet p)
overridevirtual

Read a request from the server.

Parameters
pThe packet to read the request from.
Returns
True when valid, otherwise false.

Implements NetworkAuthenticationClientHandler.

Definition at line 318 of file network_crypto.cpp.

References NetworkAuthenticationClientHandler::AWAIT_USER_INPUT, NetworkAuthenticationClientHandler::INVALID, and X25519AuthenticationHandler::ReceiveRequest().

◆ SendResponse()

virtual bool X25519PAKEClientHandler::SendResponse ( struct Packet p)
inlineoverridevirtual

Create the response to send to the server.

Parameters
pThe packet to write the response from.
Returns
True when a valid packet was made, otherwise false.

Implements NetworkAuthenticationClientHandler.

Definition at line 198 of file network_crypto_internal.h.

References X25519AuthenticationHandler::SendResponse().


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