Compare commits

..

1 Commits

Author SHA1 Message Date
feedc0de 6213a906c0 Allow the https server to request client certs only with OPTIONAL 2025-09-23 17:08:13 +02:00
6 changed files with 9 additions and 44 deletions
+3
View File
@@ -282,6 +282,9 @@ typedef struct esp_tls_cfg_server {
unsigned int cacert_pem_bytes; /*!< Size of client CA certificate legacy name */
};
bool cacert_authmode_optional; /*!< Enable this option to set the authmode
to OPTIONAL (only useful when cacert is set) */
union {
const unsigned char *servercert_buf; /*!< Server certificate in a buffer
This buffer should be NULL terminated */
+2
View File
@@ -694,6 +694,8 @@ static esp_err_t set_server_config(esp_tls_cfg_server_t *cfg, esp_tls_t *tls)
if (esp_ret != ESP_OK) {
return esp_ret;
}
if (cfg->cacert_authmode_optional)
mbedtls_ssl_conf_authmode(&tls->conf, MBEDTLS_SSL_VERIFY_OPTIONAL);
} else {
#ifdef CONFIG_ESP_TLS_SERVER_MIN_AUTH_MODE_OPTIONAL
mbedtls_ssl_conf_authmode(&tls->conf, MBEDTLS_SSL_VERIFY_OPTIONAL);
@@ -556,7 +556,6 @@ int uart_write_bytes_with_break(uart_port_t uart_num, const void* src, size_t si
/**
* @brief UART read bytes from UART buffer
* Blocks until the buffer to fill is filled completely or timeout is expired
*
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
* @param buf pointer to the buffer.
@@ -569,21 +568,6 @@ int uart_write_bytes_with_break(uart_port_t uart_num, const void* src, size_t si
*/
int uart_read_bytes(uart_port_t uart_num, void* buf, uint32_t length, TickType_t ticks_to_wait);
/**
* @brief UART read bytes from UART buffer
* Blocks until there is at least something to read (might be smaller than length!) or timeout is expired
*
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
* @param buf pointer to the buffer.
* @param length data length
* @param ticks_to_wait sTimeout, count in RTOS ticks
*
* @return
* - (-1) Error
* - OTHERS (>=0) The number of bytes read from UART buffer
*/
int uart_read_some_bytes(uart_port_t uart_num, void* buf, uint32_t length, TickType_t ticks_to_wait);
/**
* @brief Alias of uart_flush_input.
* UART ring buffer flush. This will discard all data in the UART RX buffer.
-28
View File
@@ -1653,34 +1653,6 @@ int uart_read_bytes(uart_port_t uart_num, void *buf, uint32_t length, TickType_t
return copy_len;
}
int uart_read_some_bytes(uart_port_t uart_num, void *buf, uint32_t length, TickType_t ticks_to_wait)
{
ESP_RETURN_ON_FALSE((uart_num < UART_NUM_MAX), (-1), UART_TAG, "uart_num error");
ESP_RETURN_ON_FALSE((buf), (-1), UART_TAG, "uart data null");
ESP_RETURN_ON_FALSE((p_uart_obj[uart_num]), (-1), UART_TAG, "uart driver error");
uint8_t *data = NULL;
size_t size = 0;
if (xSemaphoreTake(p_uart_obj[uart_num]->rx_mux, (TickType_t)ticks_to_wait) != pdTRUE) {
return -1;
}
data = (uint8_t *) xRingbufferReceiveUpTo(p_uart_obj[uart_num]->rx_ring_buf, &size, (TickType_t) ticks_to_wait, length);
if (!data) {
xSemaphoreGive(p_uart_obj[uart_num]->rx_mux);
return 0;
}
memcpy((uint8_t *)buf, data, size);
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
p_uart_obj[uart_num]->rx_buffered_len -= size;
uart_pattern_queue_update(uart_num, size);
UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock));
vRingbufferReturnItem(p_uart_obj[uart_num]->rx_ring_buf, data);
uart_check_buf_full(uart_num);
xSemaphoreGive(p_uart_obj[uart_num]->rx_mux);
return size;
}
esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t *size)
{
ESP_RETURN_ON_FALSE((uart_num < UART_NUM_MAX), ESP_FAIL, UART_TAG, "uart_num error");
@@ -91,6 +91,9 @@ struct httpd_ssl_config {
/** CA certificate byte length */
size_t cacert_len;
/** CA certificate verification optional */
bool cacert_authmode_optional;
/** Private key */
const uint8_t *prvtkey_pem;
@@ -278,6 +278,7 @@ static esp_err_t create_secure_context(const struct httpd_ssl_config *config, ht
cfg->userdata = config->ssl_userdata;
cfg->alpn_protos = config->alpn_protos;
cfg->tls_handshake_timeout_ms = config->tls_handshake_timeout_ms;
cfg->cacert_authmode_optional = config->cacert_authmode_optional;
#if defined(CONFIG_ESP_HTTPS_SERVER_CERT_SELECT_HOOK)
cfg->cert_select_cb = config->cert_select_cb;