15 #include <event2/event.h> 16 #include <event2/bufferevent.h> 17 #include "../mbedTLS++/SslContext.h" 61 virtual bool Send(
const void * a_Data,
size_t a_Length)
override;
66 virtual void Shutdown(
void)
override;
67 virtual void Close(
void)
override;
104 void SetSelf(cLinkTlsContextWPtr a_Self);
121 void Send(
const void * a_Data,
size_t a_Length);
124 virtual int ReceiveEncrypted(
unsigned char * a_Buffer,
size_t a_NumBytes)
override;
125 virtual int SendEncrypted(
const unsigned char * a_Buffer,
size_t a_NumBytes)
override;
130 return (a_Link == &m_Link);
179 static void ReadCallback(bufferevent * a_BufferEvent,
void * a_Self);
182 static void WriteCallback(bufferevent * a_BufferEvent,
void * a_Self);
185 static void EventCallback(bufferevent * a_BufferEvent,
short a_What,
void * a_Self);
201 bool SendRaw(
const void * a_Data,
size_t a_Length);
void FlushBuffers(void)
Tries to read any cleartext data available through the SSL, reports it in the link.
virtual int SendEncrypted(const unsigned char *a_Buffer, size_t a_NumBytes) override
static void UpdateAddress(const sockaddr *a_Address, socklen_t a_AddrLen, AString &a_IP, UInt16 &a_Port)
Sets a_IP and a_Port to values read from a_Address, based on the correct address family.
virtual AString StartTLSServer(cX509CertPtr a_OwnCert, cCryptoKeyPtr a_OwnPrivKey, const AString &a_StartTLSData) override
Starts a TLS handshake as a server connection.
void TryFinishHandshaking(void)
Tries to finish handshaking the SSL.
cServerHandleImplPtr m_Server
The server handle that has created this link.
std::shared_ptr< cX509Cert > cX509CertPtr
bool m_ShouldShutdown
If true, Shutdown() has been called and is in queue.
cNetwork::cConnectCallbacksPtr m_ConnectCallbacks
Callbacks to call when the connection is established.
void UpdateRemoteAddress(void)
Updates m_RemoteIP and m_RemotePort based on the metadata read from the socket.
virtual UInt16 GetLocalPort(void) const override
Returns the port used by the local endpoint of the connection.
bool IsLink(cTCPLinkImpl *a_Link)
Returns true if the context's associated TCP link is the same link as a_Link.
std::shared_ptr< cCryptoKey > cCryptoKeyPtr
cTCPLinkImplPtr m_Self
SharedPtr to self, used to keep this object alive as long as the callbacks are coming.
Wrapper around cSslContext that is used when this link is being encrypted by SSL. ...
AString m_LocalIP
The IP address of the local endpoint.
cLinkTlsContextWPtr m_Self
Shared ownership of self, so that this object can keep itself alive for as long as it needs...
cLinkTlsContext(cTCPLinkImpl &a_Link)
virtual UInt16 GetRemotePort(void) const override
Returns the port used by the remote endpoint of the connection.
cTCPLinkImpl(evutil_socket_t a_Socket, cCallbacksPtr a_LinkCallbacks, cServerHandleImplPtr a_Server, const sockaddr *a_Address, socklen_t a_AddrLen)
Creates a new link based on the given socket.
virtual AString StartTLSClient(cX509CertPtr a_OwnCert, cCryptoKeyPtr a_OwnPrivKey) override
Starts a TLS handshake as a client connection.
AString m_EncryptedData
Buffer for storing the incoming encrypted data until it is requested by the SSL decryptor.
std::shared_ptr< cLinkTlsContext > cLinkTlsContextPtr
virtual AString GetLocalIP(void) const override
Returns the IP address of the local endpoint of the connection.
virtual void Close(void) override
Drops the connection without any more processing.
static void EventCallback(bufferevent *a_BufferEvent, short a_What, void *a_Self)
Callback that LibEvent calls when there's a non-data-related event on the socket. ...
static void ReadCallback(bufferevent *a_BufferEvent, void *a_Self)
Callback that LibEvent calls when there's data available from the remote peer.
virtual ~cTCPLinkImpl() override
Destroys the LibEvent handle representing the link.
std::shared_ptr< cTCPLinkImpl > cTCPLinkImplPtr
void Send(const void *a_Data, size_t a_Length)
Sends the specified cleartext data over the SSL to the remote peer.
UInt16 m_LocalPort
The port of the local endpoint.
void StoreReceivedData(const char *a_Data, size_t a_NumBytes)
Stores the specified block of data into the buffer of the data to be decrypted (incoming from remote)...
void ReceivedCleartextData(const char *a_Data, size_t a_Length)
Called by the TLS when it has decoded a piece of incoming cleartext data from the socket...
void UpdateLocalAddress(void)
Updates m_LocalIP and m_LocalPort based on the metadata read from the socket.
bufferevent * m_BufferEvent
The LibEvent handle representing this connection.
void DoActualShutdown(void)
Calls shutdown on the link and disables LibEvent writing.
AString m_RemoteIP
The IP address of the remote endpoint.
std::shared_ptr< cServerHandleImpl > cServerHandleImplPtr
static void WriteCallback(bufferevent *a_BufferEvent, void *a_Self)
Callback that LibEvent calls when the remote peer can receive more data.
static cTCPLinkImplPtr Connect(const AString &a_Host, UInt16 a_Port, cTCPLink::cCallbacksPtr a_LinkCallbacks, cNetwork::cConnectCallbacksPtr a_ConnectCallbacks)
Queues a connection request to the specified host.
std::shared_ptr< cCallbacks > cCallbacksPtr
std::weak_ptr< cLinkTlsContext > cLinkTlsContextWPtr
std::shared_ptr< cServerHandleImpl > cServerHandleImplPtr
std::vector< cTCPLinkImplPtr > cTCPLinkImplPtrs
cLinkTlsContextPtr m_TlsContext
The SSL context used for encryption, if this link uses SSL.
std::shared_ptr< cConnectCallbacks > cConnectCallbacksPtr
Interface that provides the methods available on a single TCP connection.
void Enable(cTCPLinkImplPtr a_Self)
Enables communication over the link.
virtual bool Send(const void *a_Data, size_t a_Length) override
Queues the specified data for sending to the remote peer.
bool SendRaw(const void *a_Data, size_t a_Length)
Sends the data directly to the socket (without the optional TLS).
void SetSelf(cLinkTlsContextWPtr a_Self)
Shares ownership of self, so that this object can keep itself alive for as long as it needs...
virtual int ReceiveEncrypted(unsigned char *a_Buffer, size_t a_NumBytes) override
virtual AString GetRemoteIP(void) const override
Returns the IP address of the remote endpoint of the connection.
void ResetSelf(void)
Removes the self ownership so that we can detect the SSL closure.
virtual void Shutdown(void) override
Closes the link gracefully.
AString m_CleartextData
Buffer for storing the outgoing cleartext data until the link has finished handshaking.
UInt16 m_RemotePort
The port of the remote endpoint.
std::shared_ptr< cTCPLinkImpl > cTCPLinkImplPtr