diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 33b928559ab..ab96094345c 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -609,15 +609,27 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co if (config->use_global_ca_store == true) { esp_transport_ssl_enable_global_ca_store(ssl); } else if (config->cert_pem) { - esp_transport_ssl_set_cert_data(ssl, config->cert_pem, strlen(config->cert_pem)); + if (!config->cert_len) { + esp_transport_ssl_set_cert_data(ssl, config->cert_pem, strlen(config->cert_pem)); + } else { + esp_transport_ssl_set_cert_data_der(ssl, config->cert_pem, config->cert_len); + } } if (config->client_cert_pem) { - esp_transport_ssl_set_client_cert_data(ssl, config->client_cert_pem, strlen(config->client_cert_pem)); + if (!config->client_cert_len) { + esp_transport_ssl_set_client_cert_data(ssl, config->client_cert_pem, strlen(config->client_cert_pem)); + } else { + esp_transport_ssl_set_client_cert_data_der(ssl, config->client_cert_pem, config->client_cert_len); + } } if (config->client_key_pem) { - esp_transport_ssl_set_client_key_data(ssl, config->client_key_pem, strlen(config->client_key_pem)); + if (!config->client_key_len) { + esp_transport_ssl_set_client_key_data(ssl, config->client_key_pem, strlen(config->client_key_pem)); + } else { + esp_transport_ssl_set_client_key_data_der(ssl, config->client_key_pem, config->client_key_len); + } } if (config->skip_cert_common_name_check) { diff --git a/components/esp_http_client/include/esp_http_client.h b/components/esp_http_client/include/esp_http_client.h index ed4e4a32302..ee19f70cd7a 100644 --- a/components/esp_http_client/include/esp_http_client.h +++ b/components/esp_http_client/include/esp_http_client.h @@ -116,8 +116,11 @@ typedef struct { const char *path; /*!< HTTP Path, if not set, default is `/` */ const char *query; /*!< HTTP query */ const char *cert_pem; /*!< SSL server certification, PEM format as string, if the client requires to verify server */ + size_t cert_len; /*!< Length of the buffer pointed to by cert_pem. May be 0 for null-terminated pem */ const char *client_cert_pem; /*!< SSL client certification, PEM format as string, if the server requires to verify client */ + size_t client_cert_len; /*!< Length of the buffer pointed to by client_cert_pem. May be 0 for null-terminated pem */ const char *client_key_pem; /*!< SSL client key, PEM format as string, if the server requires to verify client */ + size_t client_key_len; /*!< Length of the buffer pointed to by client_key_pem. May be 0 for null-terminated pem */ const char *user_agent; /*!< The User Agent string to send with HTTP requests */ esp_http_client_method_t method; /*!< HTTP Method */ int timeout_ms; /*!< Network timeout in milliseconds */