esp_tls_private.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. /**
  8. * @brief ESP-TLS Connection Handle
  9. */
  10. #include <stdbool.h>
  11. #include <sys/socket.h>
  12. #include <fcntl.h>
  13. #include "esp_err.h"
  14. #include "esp_tls_errors.h"
  15. #ifdef CONFIG_ESP_TLS_USING_MBEDTLS
  16. #include "mbedtls/platform.h"
  17. #include "mbedtls/net_sockets.h"
  18. #include "mbedtls/esp_debug.h"
  19. #include "mbedtls/ssl.h"
  20. #include "mbedtls/entropy.h"
  21. #include "mbedtls/ctr_drbg.h"
  22. #include "mbedtls/error.h"
  23. #ifdef CONFIG_ESP_TLS_SERVER_SESSION_TICKETS
  24. #include "mbedtls/ssl_ticket.h"
  25. #endif
  26. #elif CONFIG_ESP_TLS_USING_WOLFSSL
  27. #include "wolfssl/wolfcrypt/settings.h"
  28. #include "wolfssl/ssl.h"
  29. #endif
  30. struct esp_tls {
  31. #ifdef CONFIG_ESP_TLS_USING_MBEDTLS
  32. mbedtls_ssl_context ssl; /*!< TLS/SSL context */
  33. mbedtls_entropy_context entropy; /*!< mbedTLS entropy context structure */
  34. mbedtls_ctr_drbg_context ctr_drbg; /*!< mbedTLS ctr drbg context structure.
  35. CTR_DRBG is deterministic random
  36. bit generation based on AES-256 */
  37. mbedtls_ssl_config conf; /*!< TLS/SSL configuration to be shared
  38. between mbedtls_ssl_context
  39. structures */
  40. mbedtls_net_context server_fd; /*!< mbedTLS wrapper type for sockets */
  41. mbedtls_x509_crt cacert; /*!< Container for the X.509 CA certificate */
  42. mbedtls_x509_crt *cacert_ptr; /*!< Pointer to the cacert being used. */
  43. mbedtls_x509_crt clientcert; /*!< Container for the X.509 client certificate */
  44. mbedtls_pk_context clientkey; /*!< Container for the private key of the client
  45. certificate */
  46. #ifdef CONFIG_ESP_TLS_SERVER
  47. mbedtls_x509_crt servercert; /*!< Container for the X.509 server certificate */
  48. mbedtls_pk_context serverkey; /*!< Container for the private key of the server
  49. certificate */
  50. #endif
  51. #elif CONFIG_ESP_TLS_USING_WOLFSSL
  52. void *priv_ctx;
  53. void *priv_ssl;
  54. #endif
  55. int sockfd; /*!< Underlying socket file descriptor. */
  56. ssize_t (*read)(esp_tls_t *tls, char *data, size_t datalen); /*!< Callback function for reading data from TLS/SSL
  57. connection. */
  58. ssize_t (*write)(esp_tls_t *tls, const char *data, size_t datalen); /*!< Callback function for writing data to TLS/SSL
  59. connection. */
  60. esp_tls_conn_state_t conn_state; /*!< ESP-TLS Connection state */
  61. fd_set rset; /*!< read file descriptors */
  62. fd_set wset; /*!< write file descriptors */
  63. bool is_tls; /*!< indicates connection type (TLS or NON-TLS) */
  64. esp_tls_role_t role; /*!< esp-tls role
  65. - ESP_TLS_CLIENT
  66. - ESP_TLS_SERVER */
  67. esp_tls_error_handle_t error_handle; /*!< handle to error descriptor */
  68. };