mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
ESP_TLS: Restructuring esp_tls
1)Segregating mbedtls API into seperate file and cleaned esp_tls.c 2)Added support for wolfssl for CMake and make 3)Added support for debug_wolfssl (with menuconfig option) 4)Added info on wolfssl in ESP-TLS docs
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef CONFIG_ESP_TLS_USING_MBEDTLS
|
||||
#include "mbedtls/platform.h"
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/esp_debug.h"
|
||||
@@ -27,6 +27,10 @@
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/certs.h"
|
||||
#elif CONFIG_ESP_TLS_USING_WOLFSSL
|
||||
#include "wolfssl/wolfcrypt/settings.h"
|
||||
#include "wolfssl/ssl.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -58,8 +62,8 @@ typedef struct esp_tls_last_error* esp_tls_error_handle_t;
|
||||
*/
|
||||
typedef struct esp_tls_last_error {
|
||||
esp_err_t last_error; /*!< error code (based on ESP_ERR_ESP_TLS_BASE) of the last occurred error */
|
||||
int mbedtls_error_code; /*!< mbedtls error code from last mbedtls failed api */
|
||||
int mbedtls_flags; /*!< last certification verification flags */
|
||||
int esp_tls_error_code; /*!< esp_tls error code from last esp_tls failed api */
|
||||
int esp_tls_flags; /*!< last certification verification flags */
|
||||
} esp_tls_last_error_t;
|
||||
|
||||
/**
|
||||
@@ -236,6 +240,7 @@ typedef struct esp_tls_cfg_server {
|
||||
* @brief ESP-TLS Connection Handle
|
||||
*/
|
||||
typedef struct esp_tls {
|
||||
#ifdef CONFIG_ESP_TLS_USING_MBEDTLS
|
||||
mbedtls_ssl_context ssl; /*!< TLS/SSL context */
|
||||
|
||||
mbedtls_entropy_context entropy; /*!< mbedTLS entropy context structure */
|
||||
@@ -263,6 +268,10 @@ typedef struct esp_tls {
|
||||
|
||||
mbedtls_pk_context serverkey; /*!< Container for the private key of the server
|
||||
certificate */
|
||||
#endif
|
||||
#elif CONFIG_ESP_TLS_USING_WOLFSSL
|
||||
void *priv_ctx;
|
||||
void *priv_ssl;
|
||||
#endif
|
||||
int sockfd; /*!< Underlying socket file descriptor. */
|
||||
|
||||
@@ -491,20 +500,6 @@ esp_err_t esp_tls_init_global_ca_store(void);
|
||||
*/
|
||||
esp_err_t esp_tls_set_global_ca_store(const unsigned char *cacert_pem_buf, const unsigned int cacert_pem_bytes);
|
||||
|
||||
/**
|
||||
* @brief Get the pointer to the global CA store currently being used.
|
||||
*
|
||||
* The application must first call esp_tls_set_global_ca_store(). Then the same
|
||||
* CA store could be used by the application for APIs other than esp_tls.
|
||||
*
|
||||
* @note Modifying the pointer might cause a failure in verifying the certificates.
|
||||
*
|
||||
* @return
|
||||
* - Pointer to the global CA store currently being used if successful.
|
||||
* - NULL if there is no global CA store set.
|
||||
*/
|
||||
mbedtls_x509_crt *esp_tls_get_global_ca_store(void);
|
||||
|
||||
/**
|
||||
* @brief Free the global CA store currently being used.
|
||||
*
|
||||
@@ -518,17 +513,32 @@ void esp_tls_free_global_ca_store(void);
|
||||
* The error information is cleared internally upon return
|
||||
*
|
||||
* @param[in] h esp-tls error handle.
|
||||
* @param[out] mbedtls_code last error code returned from mbedtls api (set to zero if none)
|
||||
* This pointer could be NULL if caller does not care about mbedtls_code
|
||||
* @param[out] mbedtls_flags last certification verification flags (set to zero if none)
|
||||
* This pointer could be NULL if caller does not care about mbedtls_flags
|
||||
* @param[out] esp_tls_code last error code returned from mbedtls api (set to zero if none)
|
||||
* This pointer could be NULL if caller does not care about esp_tls_code
|
||||
* @param[out] esp_tls_flags last certification verification flags (set to zero if none)
|
||||
* This pointer could be NULL if caller does not care about esp_tls_code
|
||||
*
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_STATE if invalid parameters
|
||||
* - ESP_OK (0) if no error occurred
|
||||
* - specific error code (based on ESP_ERR_ESP_TLS_BASE) otherwise
|
||||
*/
|
||||
esp_err_t esp_tls_get_and_clear_last_error(esp_tls_error_handle_t h, int *mbedtls_code, int *mbedtls_flags);
|
||||
esp_err_t esp_tls_get_and_clear_last_error(esp_tls_error_handle_t h, int *esp_tls_code, int *esp_tls_flags);
|
||||
|
||||
#if CONFIG_ESP_TLS_USING_MBEDTLS
|
||||
/**
|
||||
* @brief Get the pointer to the global CA store currently being used.
|
||||
*
|
||||
* The application must first call esp_tls_set_global_ca_store(). Then the same
|
||||
* CA store could be used by the application for APIs other than esp_tls.
|
||||
*
|
||||
* @note Modifying the pointer might cause a failure in verifying the certificates.
|
||||
*
|
||||
* @return
|
||||
* - Pointer to the global CA store currently being used if successful.
|
||||
* - NULL if there is no global CA store set.
|
||||
*/
|
||||
mbedtls_x509_crt *esp_tls_get_global_ca_store(void);
|
||||
|
||||
#ifdef CONFIG_ESP_TLS_SERVER
|
||||
/**
|
||||
@@ -557,6 +567,7 @@ int esp_tls_server_session_create(esp_tls_cfg_server_t *cfg, int sockfd, esp_tls
|
||||
*/
|
||||
void esp_tls_server_session_delete(esp_tls_t *tls);
|
||||
#endif /* ! CONFIG_ESP_TLS_SERVER */
|
||||
#endif /* CONFIG_ESP_TLS_USING_MBEDTLS */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user