Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MutualAuthentication in HTTPS-Server (IDFGH-2004) #4184

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions components/esp_https_server/include/esp_https_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ struct httpd_ssl_config {
/** CA certificate byte length */
size_t cacert_len;

/** Server certificate */
const uint8_t *servercert_pem;

/** Server certificate byte length */
size_t servercert_len;

/** Private key */
const uint8_t *prvtkey_pem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will break public API and hence build for examples like https_server, esp_local_control. Can you please revert this?


Expand Down Expand Up @@ -100,6 +106,8 @@ typedef struct httpd_ssl_config httpd_ssl_config_t;
}, \
.cacert_pem = NULL, \
.cacert_len = 0, \
.servercert_pem = NULL, \
.servercert_len = 0, \
.prvtkey_pem = NULL, \
.prvtkey_len = 0, \
.transport_mode = HTTPD_SSL_TRANSPORT_SECURE, \
Expand Down
15 changes: 14 additions & 1 deletion components/esp_https_server/src/https_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ static void free_secure_context(void *ctx)
assert(ctx != NULL);
esp_tls_cfg_server_t *cfg = (esp_tls_cfg_server_t *)ctx;
ESP_LOGI(TAG, "Server shuts down, releasing SSL context");
if (cfg->cacert_buf) {
free((void *)cfg->cacert_buf);
}
if (cfg->servercert_buf) {
free((void *)cfg->servercert_buf);
}
Expand All @@ -150,17 +153,27 @@ static esp_tls_cfg_server_t *create_secure_context(const struct httpd_ssl_config
if (!cfg) {
return NULL;
}
cfg->cacert_buf = (unsigned char *)malloc(config->cacert_len);
if (!cfg->cacert_buf) {
free(cfg);
return NULL;
}
memcpy((char *)cfg->cacert_buf, config->cacert_pem, config->cacert_len);
cfg->cacert_bytes = config->cacert_len;

cfg->servercert_buf = (unsigned char *)malloc(config->cacert_len);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be
cfg->servercert_buf = (unsigned char *)malloc(config->servercert_len);

if (!cfg->servercert_buf) {
free((void *)cfg->cacert_buf);
free(cfg);
return NULL;
}
memcpy((char *)cfg->servercert_buf, config->cacert_pem, config->cacert_len);
memcpy((char *)cfg->servercert_buf, config->servercert_pem, config->servercert_len);
cfg->servercert_bytes = config->cacert_len;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be
cfg->servercert_bytes = config->servercert_len;


cfg->serverkey_buf = (unsigned char *)malloc(config->prvtkey_len);
if (!cfg->serverkey_buf) {
free((void *)cfg->servercert_buf);
free((void *)cfg->cacert_buf);
free(cfg);
return NULL;
}
Expand Down