tls_socket_mbedtls.c File Reference

TLS Socket implementation file using mbedTLS. More...

#include "../mcl_tls_socket.h"
#include "mcl_core/mcl_memory.h"
#include "mcl_core/mcl_string_util.h"
#include "mcl_core/mcl_log_util.h"
#include "mbedtls/ssl.h"
#include "mbedtls/entropy.h"
#include "mbedtls/net_sockets.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/debug.h"
Include dependency graph for tls_socket_mbedtls.c:

Go to the source code of this file.

Data Structures

struct  mcl_tls_socket_handle
 
struct  mcl_tls_ca_chain_handle
 

Macros

#define PORT_STRING_BUFFER_SIZE   6
 

Functions

static void mbedtls_debug_function (void *ctx, int level, const char *file, int line, const char *str)
 
mcl_error_t mcl_tls_ca_chain_init (mcl_tls_ca_chain_handle *tls_ca_chain_handle)
 
mcl_error_t mcl_tls_ca_chain_add_certificate (mcl_tls_ca_chain_handle tls_ca_chain_handle, const char *certificate, mcl_bool_t is_file)
 
void mcl_tls_ca_chain_destroy (mcl_tls_ca_chain_handle *tls_ca_chain_handle)
 
mcl_error_t mcl_tls_socket_init (mcl_tls_socket_handle *tls_socket_handle)
 
mcl_error_t mcl_tls_socket_set_parameter (mcl_tls_socket_handle tls_socket_handle, E_MCL_TLS_SOCKET_PARAMETER parameter, const void *value)
 
mcl_error_t mcl_tls_socket_open (mcl_tls_socket_handle tls_socket_handle)
 
mcl_error_t mcl_tls_socket_connect (mcl_tls_socket_handle tls_socket_handle, const char *host, mcl_uint16_t port)
 
mcl_error_t mcl_tls_socket_send (mcl_tls_socket_handle tls_socket_handle, const mcl_uint8_t *buffer, mcl_size_t *size)
 
mcl_error_t mcl_tls_socket_receive (mcl_tls_socket_handle tls_socket_handle, mcl_uint8_t *buffer, mcl_size_t *size)
 
void mcl_tls_socket_destroy (mcl_tls_socket_handle *tls_socket_handle)
 

Variables

static const unsigned char entropy_string [] = "MCL TLS socket wrapper using mbedTLS."
 

Detailed Description

TLS Socket implementation file using mbedTLS.

Definition in file tls_socket_mbedtls.c.

Macro Definition Documentation

#define PORT_STRING_BUFFER_SIZE   6

Definition at line 19 of file tls_socket_mbedtls.c.

Referenced by mcl_tls_socket_connect().

Function Documentation

static void mbedtls_debug_function ( void *  ctx,
int  level,
const char *  file,
int  line,
const char *  str 
)
static

Definition at line 58 of file tls_socket_mbedtls.c.

References MCL_LOG_ENABLED_RUN_TIME, MCL_LOG_LEVEL_DEBUG, MCL_LOG_LEVEL_ERROR, MCL_LOG_LEVEL_VERBOSE, mcl_log_util_function, and mcl_log_util_user_context.

Referenced by mcl_tls_socket_init().

Here is the caller graph for this function:

mcl_error_t mcl_tls_ca_chain_add_certificate ( mcl_tls_ca_chain_handle  tls_ca_chain_handle,
const char *  certificate,
mcl_bool_t  is_file 
)

This function creates and initializes a #mcl_tls_ca_chain_handle.

Parameters
[in]tls_ca_chain_handleCertificate chain handle.
[in]certificateCertificate.
[in]is_fileMCL_TRUE if certificate is given as file, MCL_FALSE otherwise.
Returns

Definition at line 126 of file tls_socket_mbedtls.c.

References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR_RETURN, MCL_IMPROPER_CERTIFICATE, MCL_NULL_CHAR_SIZE, MCL_OK, MCL_OPERATION_NOT_SUPPORTED, MCL_OUT_OF_MEMORY, mcl_string_util_strlen(), and MCL_TRUE.

Referenced by mcl_http_client_add_certificate(), and mcl_http_client_initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

void mcl_tls_ca_chain_destroy ( mcl_tls_ca_chain_handle *  tls_ca_chain_handle)

This function destroys the #mcl_tls_ca_chain_handle and frees any memory allocated.

Parameters
[in]tls_ca_chain_handlePreinitialized #mcl_tls_ca_chain_handle to destroy.

Definition at line 166 of file tls_socket_mbedtls.c.

References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and MCL_FREE.

Referenced by mcl_http_client_destroy().

Here is the caller graph for this function:

mcl_error_t mcl_tls_ca_chain_init ( mcl_tls_ca_chain_handle *  tls_ca_chain_handle)

This function creates and initializes a #mcl_tls_ca_chain_handle.

Parameters
[out]tls_ca_chain_handleCertificate chain handle.
Returns

Definition at line 102 of file tls_socket_mbedtls.c.

References MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, MCL_MALLOC, MCL_OK, and MCL_OUT_OF_MEMORY.

Referenced by mcl_http_client_initialize().

Here is the caller graph for this function:

mcl_error_t mcl_tls_socket_connect ( mcl_tls_socket_handle  tls_socket_handle,
const char *  host,
mcl_uint16_t  port 
)

This function connects TLS socket to a remote host.

Parameters
[in]tls_socket_handleTLS socket handle.
[in]hostHost to connect.
[in]portPort.
Returns

Definition at line 294 of file tls_socket_mbedtls.c.

References MCL_COULD_NOT_CONNECT, MCL_COULD_NOT_RESOLVE_HOST, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_FAIL, MCL_INVALID_PARAMETER, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_SERVER_CERTIFICATE_NOT_VERIFIED, MCL_SSL_HANDSHAKE_FAIL, mcl_string_util_snprintf(), MCL_TRIGGERED_WITH_NULL, and PORT_STRING_BUFFER_SIZE.

Referenced by start_http().

Here is the call graph for this function:

Here is the caller graph for this function:

void mcl_tls_socket_destroy ( mcl_tls_socket_handle *  tls_socket_handle)

This function destroys the #mcl_tls_socket_handle and frees any memory allocated.

Parameters
[in]tls_ca_chain_handlePreinitialized #mcl_tls_socket_handle to destroy.

Definition at line 489 of file tls_socket_mbedtls.c.

References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, and MCL_NULL.

Referenced by mcl_http_client_send(), and mcl_tls_socket_init().

Here is the caller graph for this function:

mcl_error_t mcl_tls_socket_init ( mcl_tls_socket_handle *  tls_socket_handle)

This function creates and initializes a #mcl_tls_socket_handle.

Parameters
[out]tls_socket_handleTLS socket handle.
Returns

Definition at line 179 of file tls_socket_mbedtls.c.

References entropy_string, mbedtls_debug_function(), MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FAIL, MCL_FUNCTION_LEAVE_LABEL, MCL_LOG_ENABLED_COMPILE_TIME, MCL_LOG_LEVEL_DEBUG, MCL_LOG_LEVEL_ERROR, MCL_LOG_LEVEL_VERBOSE, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR_SIZE, MCL_OK, MCL_OUT_OF_MEMORY, and mcl_tls_socket_destroy().

Referenced by mcl_http_client_send().

Here is the call graph for this function:

Here is the caller graph for this function:

mcl_error_t mcl_tls_socket_open ( mcl_tls_socket_handle  tls_socket_handle)

This function is used to open a TLS socket.

Parameters
[in]tls_socket_handleTLS socket handle.
Returns

Definition at line 279 of file tls_socket_mbedtls.c.

References MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, and MCL_OK.

Referenced by mcl_http_client_send().

Here is the caller graph for this function:

mcl_error_t mcl_tls_socket_receive ( mcl_tls_socket_handle  tls_socket_handle,
mcl_uint8_t buffer,
mcl_size_t buffer_length 
)

This function is used to receive data over TLS socket.

Parameters
[in]tls_socket_handleTLS socket handle.
[out]bufferBuffer to write the received data.
[in,out]buffer_lengthSize of the buffer in bytes. It will be set to size of bytes successfully received.
Returns

Definition at line 451 of file tls_socket_mbedtls.c.

References MCL_ERROR, MCL_FAIL, MCL_INVALID_PARAMETER, MCL_OK, MCL_TRIGGERED_WITH_NULL, MCL_VERBOSE_ENTRY, and MCL_VERBOSE_LEAVE.

Referenced by receive_to_buffer(), and receive_until_lf().

Here is the caller graph for this function:

mcl_error_t mcl_tls_socket_send ( mcl_tls_socket_handle  tls_socket_handle,
const mcl_uint8_t buffer,
mcl_size_t buffer_length 
)

This function is used to send data over TLS socket.

Parameters
[in]tls_socket_handleTLS socket handle.
[in]bufferBuffer to be sent.
[in,out]buffer_lengthSize of the buffer in bytes. It will be set to size of bytes successfully sent.
Returns

Definition at line 412 of file tls_socket_mbedtls.c.

References MCL_ERROR, MCL_FAIL, MCL_INVALID_PARAMETER, MCL_OK, MCL_TRIGGERED_WITH_NULL, MCL_VERBOSE_ENTRY, and MCL_VERBOSE_LEAVE.

Referenced by send_buffer().

Here is the caller graph for this function:

mcl_error_t mcl_tls_socket_set_parameter ( mcl_tls_socket_handle  tls_socket_handle,
E_MCL_TLS_SOCKET_PARAMETER  parameter,
const void *  value 
)

This function is used to set a parameter of a TLS socket handle.

Parameters
[in]tls_socket_handleTLS socket handle.
[in]parameterOne of the parameters listed in E_MCL_TLS_SOCKET_PARAMETER.
[in]valueNew value of the parameter.
Returns

Definition at line 251 of file tls_socket_mbedtls.c.

References MCL_ASSERT_NOT_NULL, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, MCL_INVALID_PARAMETER, MCL_NULL, MCL_OK, MCL_TLS_SOCKET_PARAMETER_CERTIFICATE_CHAIN, and MCL_TLS_SOCKET_PARAMETER_TIMEOUT.

Referenced by mcl_http_client_send().

Here is the caller graph for this function:

Variable Documentation

const unsigned char entropy_string[] = "MCL TLS socket wrapper using mbedTLS."
static

Definition at line 21 of file tls_socket_mbedtls.c.

Referenced by mcl_tls_socket_init().