mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 20:41:14 +00:00
Merge branch 'fix/make_esp_tls_t_private' into 'master'
Make esp_tls_t as private structure Closes IDF-2812 See merge request espressif/esp-idf!17812
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <esp_https_server.h>
|
||||
#include "esp_tls.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
/* A simple example that demonstrates how to create GET and POST
|
||||
* handlers and start an HTTPS server.
|
||||
@@ -36,7 +37,7 @@ static esp_err_t root_get_handler(httpd_req_t *req)
|
||||
}
|
||||
|
||||
#if CONFIG_EXAMPLE_ENABLE_HTTPS_USER_CALLBACK
|
||||
|
||||
#ifdef CONFIG_ESP_TLS_USING_MBEDTLS
|
||||
static void print_peer_cert_info(const mbedtls_ssl_context *ssl)
|
||||
{
|
||||
const mbedtls_x509_crt *cert;
|
||||
@@ -58,7 +59,7 @@ static void print_peer_cert_info(const mbedtls_ssl_context *ssl)
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Example callback function to get the certificate of connected clients,
|
||||
* whenever a new SSL connection is created and closed
|
||||
@@ -75,22 +76,44 @@ static void print_peer_cert_info(const mbedtls_ssl_context *ssl)
|
||||
static void https_server_user_callback(esp_https_server_user_cb_arg_t *user_cb)
|
||||
{
|
||||
ESP_LOGI(TAG, "User callback invoked!");
|
||||
|
||||
#ifdef CONFIG_ESP_TLS_USING_MBEDTLS
|
||||
mbedtls_ssl_context *ssl_ctx = NULL;
|
||||
#endif
|
||||
switch(user_cb->user_cb_state) {
|
||||
case HTTPD_SSL_USER_CB_SESS_CREATE:
|
||||
ESP_LOGD(TAG, "At session creation");
|
||||
|
||||
// Logging the socket FD
|
||||
ESP_LOGI(TAG, "Socket FD: %d", user_cb->tls->sockfd);
|
||||
|
||||
int sockfd = -1;
|
||||
esp_err_t esp_ret;
|
||||
esp_ret = esp_tls_get_conn_sockfd(user_cb->tls, &sockfd);
|
||||
if (esp_ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Error in obtaining the sockfd from tls context");
|
||||
break;
|
||||
}
|
||||
ESP_LOGI(TAG, "Socket FD: %d", sockfd);
|
||||
#ifdef CONFIG_ESP_TLS_USING_MBEDTLS
|
||||
ssl_ctx = (mbedtls_ssl_context *) esp_tls_get_ssl_context(user_cb->tls);
|
||||
if (ssl_ctx == NULL) {
|
||||
ESP_LOGE(TAG, "Error in obtaining ssl context");
|
||||
break;
|
||||
}
|
||||
// Logging the current ciphersuite
|
||||
ESP_LOGI(TAG, "Current Ciphersuite: %s", mbedtls_ssl_get_ciphersuite(&user_cb->tls->ssl));
|
||||
ESP_LOGI(TAG, "Current Ciphersuite: %s", mbedtls_ssl_get_ciphersuite(ssl_ctx));
|
||||
#endif
|
||||
break;
|
||||
|
||||
case HTTPD_SSL_USER_CB_SESS_CLOSE:
|
||||
ESP_LOGD(TAG, "At session close");
|
||||
|
||||
#ifdef CONFIG_ESP_TLS_USING_MBEDTLS
|
||||
// Logging the peer certificate
|
||||
print_peer_cert_info(&user_cb->tls->ssl);
|
||||
ssl_ctx = (mbedtls_ssl_context *) esp_tls_get_ssl_context(user_cb->tls);
|
||||
if (ssl_ctx == NULL) {
|
||||
ESP_LOGE(TAG, "Error in obtaining ssl context");
|
||||
break;
|
||||
}
|
||||
print_peer_cert_info(ssl_ctx);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
ESP_LOGE(TAG, "Illegal state!");
|
||||
|
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <esp_https_server.h>
|
||||
#include "keep_alive.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#if !CONFIG_HTTPD_WS_SUPPORT
|
||||
#error This example cannot be used unless HTTPD_WS_SUPPORT is enabled in esp-http-server component configuration
|
||||
|
Reference in New Issue
Block a user