9 #include "../mbedTLS++/X509Cert.h" 10 #include "../mbedTLS++/CryptoKey.h" 17 m_Callbacks(
std::move(a_Callbacks))
61 return link->Send(a_Data);
78 return link->GetLocalIP();
95 return link->GetLocalPort();
112 return link->GetRemoteIP();
129 return link->GetRemotePort();
168 const AString & a_OwnPrivKeyData,
169 const AString & a_OwnPrivKeyPassword
176 if (!a_OwnCertData.empty())
178 ownCert = std::make_shared<cX509Cert>();
179 auto res = ownCert->Parse(a_OwnCertData.data(), a_OwnCertData.size());
182 return Printf(
"Cannot parse client certificate: -0x%x", res);
186 if (!a_OwnPrivKeyData.empty())
188 ownPrivKey = std::make_shared<cCryptoKey>();
189 auto res = ownPrivKey->ParsePrivate(a_OwnPrivKeyData.data(), a_OwnPrivKeyData.size(), a_OwnPrivKeyPassword);
192 return Printf(
"Cannot parse client private key: -0x%x", res);
195 return link->StartTLSClient(ownCert, ownPrivKey);
206 const AString & a_OwnPrivKeyData,
207 const AString & a_OwnPrivKeyPassword,
215 auto OwnCert = std::make_shared<cX509Cert>();
216 int res = OwnCert->Parse(a_OwnCertData.data(), a_OwnCertData.size());
219 return Printf(
"Cannot parse server certificate: -0x%x", res);
221 auto OwnPrivKey = std::make_shared<cCryptoKey>();
222 res = OwnPrivKey->ParsePrivate(a_OwnPrivKeyData.data(), a_OwnPrivKeyData.size(), a_OwnPrivKeyPassword);
225 return Printf(
"Cannot parse server private key: -0x%x", res);
228 return link->StartTLSServer(OwnCert, OwnPrivKey, a_StartTLSData);
247 if (Server !=
nullptr)
249 Server->RemoveLink(
this);
290 m_Callbacks->CallTableFn(
"OnError",
this, a_ErrorCode, a_ErrorMsg);
virtual void OnReceivedData(const char *a_Data, size_t a_Length) override
Called when there's data incoming from the remote peer.
std::unique_ptr< cTableRef > cTableRefPtr
std::shared_ptr< cX509Cert > cX509CertPtr
AString StartTLSServer(const AString &a_OwnCertData, const AString &a_OwnPrivKeyData, const AString &a_OwnPrivKeyPassword, const AString &a_StartTLSData)
Starts a TLS handshake as a server connection.
AString GetRemoteIP(void) const
Returns the IP address of the remote endpoint of the connection.
std::shared_ptr< cCryptoKey > cCryptoKeyPtr
void Terminated(void)
Common code called when the link is considered as terminated.
bool Send(const AString &a_Data)
Sends the data contained in the string to the remote peer.
UInt16 GetLocalPort(void) const
Returns the port used by the local endpoint of the connection.
void Shutdown(void)
Closes the link gracefully.
cLuaServerHandleWPtr m_Server
The server that is responsible for this link, if any.
void ReceivedCleartextData(const char *a_Data, size_t a_NumBytes)
Called by the SSL context when there's incoming data available in the cleartext.
std::shared_ptr< cTCPLink > cTCPLinkPtr
virtual ~cLuaTCPLink() override
cTCPLinkPtr m_Link
The underlying link representing the connection.
AString & Printf(AString &str, const char *format, fmt::ArgList args)
Output the formatted text into the string.
cLuaTCPLink(cLuaState::cTableRefPtr &&a_Callbacks)
Creates a new instance of the link, wrapping the callbacks that are in the specified table...
std::weak_ptr< cLuaServerHandle > cLuaServerHandleWPtr
void Close(void)
Drops the connection without any more processing.
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override
Called when the cTCPLink for the connection is created.
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when an error is detected on the connection.
Interface that provides the methods available on a single TCP connection.
UInt16 GetRemotePort(void) const
Returns the port used by the remote endpoint of the connection.
AString StartTLSClient(const AString &a_OwnCertData, const AString &a_OwnPrivKeyData, const AString &a_OwnPrivKeyPassword)
Starts a TLS handshake as a client connection.
AString GetLocalIP(void) const
Returns the IP address of the local endpoint of the connection.
cLuaState::cTableRefPtr m_Callbacks
The Lua table that holds the callbacks to be invoked.
virtual void OnRemoteClosed(void) override
Called when the remote end closes the connection.
virtual void OnConnected(cTCPLink &a_Link) override
Called when the Connect call succeeds.