mirror of
https://github.com/eledio-devices/thirdparty-AsyncTCPSock.git
synced 2025-10-30 16:15:40 +01:00
Add methods for reading and writing data to TLS connection
This commit is contained in:
@@ -235,6 +235,30 @@ int AsyncTCP_TLS_Context::runSSLHandshake(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AsyncTCP_TLS_Context::write(const uint8_t *data, size_t len)
|
||||
{
|
||||
if (_socket < 0) return -1;
|
||||
|
||||
log_v("Writing packet, %d bytes unencrypted...", len);
|
||||
int ret = mbedtls_ssl_write(&ssl_ctx, data, len);
|
||||
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret < 0) {
|
||||
log_v("Handling error %d", ret); //for low level debug
|
||||
return handle_error(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AsyncTCP_TLS_Context::read(uint8_t * data, size_t len)
|
||||
{
|
||||
int ret = mbedtls_ssl_read(&ssl_ctx, data, len);
|
||||
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret < 0) {
|
||||
log_v("Handling error %d", ret); //for low level debug
|
||||
return handle_error(ret);
|
||||
}
|
||||
if (ret > 0) log_v("Read packet, %d out of %d requested bytes...", ret, len);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AsyncTCP_TLS_Context::_deleteHandshakeCerts(void)
|
||||
{
|
||||
if (_have_ca_cert) {
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
#define ASYNCTCP_TLS_CAN_RETRY(r) (((r) == MBEDTLS_ERR_SSL_WANT_READ) || ((r) == MBEDTLS_ERR_SSL_WANT_WRITE))
|
||||
|
||||
class AsyncTCP_TLS_Context
|
||||
{
|
||||
private:
|
||||
@@ -50,6 +52,10 @@ public:
|
||||
const char *psKey, bool insecure);
|
||||
|
||||
int runSSLHandshake(void);
|
||||
|
||||
int write(const uint8_t *data, size_t len);
|
||||
|
||||
int read(uint8_t * data, size_t len);
|
||||
};
|
||||
|
||||
#endif // ASYNC_TCP_SSL_ENABLED
|
||||
Reference in New Issue
Block a user