Cuberite
A lightweight, fast and extensible game server for Minecraft
|
#include <BlockingSslClientSocket.h>
Public Member Functions | |
cBlockingSslClientSocket (void) | |
bool | Connect (const AString &a_ServerName, UInt16 a_Port) |
Connects to the specified server and performs SSL handshake. More... | |
void | Disconnect (void) |
Disconnects the connection gracefully, if possible. More... | |
const AString & | GetLastErrorText (void) const |
Returns the text of the last error that has occurred in this instance. More... | |
int | Receive (void *a_Data, size_t a_MaxBytes) |
Receives data from the connection. More... | |
bool | Send (const void *a_Data, size_t a_NumBytes) |
Sends the specified data over the connection. More... | |
void | SetExpectedPeerName (AString a_ExpectedPeerName) |
Sets the Expected peer name. More... | |
void | SetSslConfig (std::shared_ptr< const cSslConfig > a_Config) |
Set the config to be used by the SSL context. More... | |
virtual | ~cBlockingSslClientSocket (void) override |
Protected Member Functions | |
void | OnConnected (void) |
Called when the connection is established successfully. More... | |
void | OnConnectError (const AString &a_ErrorMsg) |
Called when an error occurs while connecting the socket. More... | |
void | OnDisconnected (void) |
Called when the link is disconnected, either gracefully or by an error. More... | |
void | OnReceivedData (const char *a_Data, size_t a_Size) |
Called when there's incoming data from the socket. More... | |
virtual int | ReceiveEncrypted (unsigned char *a_Buffer, size_t a_NumBytes) override |
Called when mbedTLS wants to read encrypted data from the SSL peer. More... | |
virtual int | SendEncrypted (const unsigned char *a_Buffer, size_t a_NumBytes) override |
Called when mbedTLS wants to write encrypted data to the SSL peer. More... | |
void | SetLink (cTCPLinkPtr a_Link) |
Called when the link for the connection is created. More... | |
Protected Member Functions inherited from cCallbackSslContext::cDataCallbacks | |
virtual | ~cDataCallbacks () |
Protected Attributes | |
std::shared_ptr< const cSslConfig > | m_Config |
The configuration to be used by the SSL context. More... | |
cCriticalSection | m_CSIncomingData |
Protects m_IncomingData against multithreaded access. More... | |
cEvent | m_Event |
The object used to signal state changes in the socket (the cause of the blocking). More... | |
AString | m_ExpectedPeerName |
The expected SSL peer's name, if we are to verify the cert strictly. More... | |
AString | m_IncomingData |
Buffer for the data incoming on the network socket. More... | |
std::atomic< bool > | m_IsConnected |
Set to true if the connection established successfully. More... | |
AString | m_LastErrorText |
Text of the last error that has occurred. More... | |
AString | m_ServerName |
The hostname to which the socket is connecting (stored for error reporting). More... | |
cTCPLinkPtr | m_Socket |
The underlying socket to the SSL server. More... | |
cCallbackSslContext | m_Ssl |
The SSL context used for the socket. More... | |
Friends | |
class | cBlockingSslClientSocketConnectCallbacks |
class | cBlockingSslClientSocketLinkCallbacks |
Definition at line 19 of file BlockingSslClientSocket.h.
cBlockingSslClientSocket::cBlockingSslClientSocket | ( | void | ) |
Definition at line 89 of file BlockingSslClientSocket.cpp.
|
inlineoverridevirtual |
Definition at line 25 of file BlockingSslClientSocket.h.
Connects to the specified server and performs SSL handshake.
Returns true if successful, false on failure. Sets internal error text on failure.
Definition at line 100 of file BlockingSslClientSocket.cpp.
void cBlockingSslClientSocket::Disconnect | ( | void | ) |
Disconnects the connection gracefully, if possible.
Note that this also frees the internal SSL context, so all the certificates etc. are lost.
Definition at line 253 of file BlockingSslClientSocket.cpp.
|
inline |
Returns the text of the last error that has occurred in this instance.
Definition at line 59 of file BlockingSslClientSocket.h.
|
protected |
Called when the connection is established successfully.
Definition at line 324 of file BlockingSslClientSocket.cpp.
|
protected |
Called when an error occurs while connecting the socket.
Definition at line 334 of file BlockingSslClientSocket.cpp.
|
protected |
Called when the link is disconnected, either gracefully or by an error.
Definition at line 366 of file BlockingSslClientSocket.cpp.
|
protected |
Called when there's incoming data from the socket.
Definition at line 344 of file BlockingSslClientSocket.cpp.
int cBlockingSslClientSocket::Receive | ( | void * | a_Data, |
size_t | a_MaxBytes | ||
) |
Receives data from the connection.
Blocks until there is any data available, then returns as much as possible. Returns the number of bytes actually received, negative number on failure. Sets the internal error text on failure.
Definition at line 238 of file BlockingSslClientSocket.cpp.
|
overrideprotectedvirtual |
Called when mbedTLS wants to read encrypted data from the SSL peer.
The returned value is the number of bytes received, or a mbedTLS error on failure. The implementation can return MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE to indicate that there's currently no more data and that there might be more data in the future. In such cases the SSL operation that invoked this call will terminate with the same return value, so that the owner is notified of this condition and can potentially restart the operation later on.
Implements cCallbackSslContext::cDataCallbacks.
Definition at line 278 of file BlockingSslClientSocket.cpp.
bool cBlockingSslClientSocket::Send | ( | const void * | a_Data, |
size_t | a_NumBytes | ||
) |
Sends the specified data over the connection.
Returns true if successful, false on failure. Sets the internal error text on failure.
Definition at line 201 of file BlockingSslClientSocket.cpp.
|
overrideprotectedvirtual |
Called when mbedTLS wants to write encrypted data to the SSL peer.
The returned value is the number of bytes sent, or a mbedTLS error on failure. The implementation can return MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE to indicate that there's currently no more data and that there might be more data in the future. In such cases the SSL operation that invoked this call will terminate with the same return value, so that the owner is notified of this condition and can potentially restart the operation later on.
Implements cCallbackSslContext::cDataCallbacks.
Definition at line 305 of file BlockingSslClientSocket.cpp.
void cBlockingSslClientSocket::SetExpectedPeerName | ( | AString | a_ExpectedPeerName | ) |
Sets the Expected peer name.
Needs to be used before calling Connect().
a_ExpectedPeerName | Name that we expect to receive in the SSL peer's cert; verification will fail if the presented name is different (possible MITM). |
Definition at line 164 of file BlockingSslClientSocket.cpp.
|
protected |
Called when the link for the connection is created.
Definition at line 357 of file BlockingSslClientSocket.cpp.
void cBlockingSslClientSocket::SetSslConfig | ( | std::shared_ptr< const cSslConfig > | a_Config | ) |
Set the config to be used by the SSL context.
Config must not be modified after calling connect.
Definition at line 184 of file BlockingSslClientSocket.cpp.
|
friend |
Definition at line 62 of file BlockingSslClientSocket.h.
|
friend |
Definition at line 63 of file BlockingSslClientSocket.h.
|
protected |
The configuration to be used by the SSL context.
Set by SetSslConfig().
Definition at line 75 of file BlockingSslClientSocket.h.
|
protected |
Protects m_IncomingData against multithreaded access.
Definition at line 90 of file BlockingSslClientSocket.h.
|
protected |
The object used to signal state changes in the socket (the cause of the blocking).
Definition at line 72 of file BlockingSslClientSocket.h.
|
protected |
The expected SSL peer's name, if we are to verify the cert strictly.
Set by SetExpectedPeerName().
Definition at line 78 of file BlockingSslClientSocket.h.
|
protected |
Buffer for the data incoming on the network socket.
Protected by m_CSIncomingData.
Definition at line 94 of file BlockingSslClientSocket.h.
|
protected |
Set to true if the connection established successfully.
Definition at line 87 of file BlockingSslClientSocket.h.
|
protected |
Text of the last error that has occurred.
Definition at line 84 of file BlockingSslClientSocket.h.
|
protected |
The hostname to which the socket is connecting (stored for error reporting).
Definition at line 81 of file BlockingSslClientSocket.h.
|
protected |
The underlying socket to the SSL server.
Definition at line 69 of file BlockingSslClientSocket.h.
|
protected |
The SSL context used for the socket.
Definition at line 66 of file BlockingSslClientSocket.h.