2017-09-19 04:34:08 -04:00
|
|
|
|
2014-04-27 16:27:53 -04:00
|
|
|
// CallbackSslContext.cpp
|
|
|
|
|
|
|
|
// Declares the cCallbackSslContext class representing a SSL context wrapper that uses callbacks to read and write SSL peer data
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "CallbackSslContext.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-04 05:58:09 -04:00
|
|
|
cCallbackSslContext::cCallbackSslContext(void) :
|
2014-10-20 16:55:07 -04:00
|
|
|
m_Callbacks(nullptr)
|
2014-04-27 16:27:53 -04:00
|
|
|
{
|
|
|
|
// Nothing needed, but the constructor needs to exist so
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cCallbackSslContext::cCallbackSslContext(cCallbackSslContext::cDataCallbacks & a_Callbacks) :
|
|
|
|
m_Callbacks(&a_Callbacks)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cCallbackSslContext::ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_Callbacks == nullptr)
|
2014-04-27 16:27:53 -04:00
|
|
|
{
|
|
|
|
LOGWARNING("SSL: Trying to receive data with no callbacks, aborting.");
|
2017-08-30 10:00:06 -04:00
|
|
|
return MBEDTLS_ERR_NET_RECV_FAILED;
|
2014-04-27 16:27:53 -04:00
|
|
|
}
|
|
|
|
return m_Callbacks->ReceiveEncrypted(a_Buffer, a_NumBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cCallbackSslContext::SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_Callbacks == nullptr)
|
2014-04-27 16:27:53 -04:00
|
|
|
{
|
|
|
|
LOGWARNING("SSL: Trying to send data with no callbacks, aborting.");
|
2017-08-30 10:00:06 -04:00
|
|
|
return MBEDTLS_ERR_NET_SEND_FAILED;
|
2014-04-27 16:27:53 -04:00
|
|
|
}
|
|
|
|
return m_Callbacks->SendEncrypted(a_Buffer, a_NumBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|