*/
void esp_transport_ssl_set_cert_data(esp_transport_handle_t t, const char *data, int len);
+/**
+ * @brief Set SSL client certificate data for mutual authentication (as PEM format).
+ * Note that, this function stores the pointer to data, rather than making a copy.
+ * So we need to make sure to keep the data lifetime before cleanup the connection
+ *
+ * @param t ssl transport
+ * @param[in] data The pem data
+ * @param[in] len The length
+ */
+void esp_transport_ssl_set_client_cert_data(esp_transport_handle_t t, const char *data, int len);
+
+/**
+ * @brief Set SSL client key data for mutual authentication (as PEM format).
+ * Note that, this function stores the pointer to data, rather than making a copy.
+ * So we need to make sure to keep the data lifetime before cleanup the connection
+ *
+ * @param t ssl transport
+ * @param[in] data The pem data
+ * @param[in] len The length
+ */
+void esp_transport_ssl_set_client_key_data(esp_transport_handle_t t, const char *data, int len);
#ifdef __cplusplus
}
esp_tls_cfg_t cfg;
bool ssl_initialized;
bool verify_server;
+ bool mutual_authentication;
transport_ssl_conn_state_t conn_state;
} transport_ssl_t;
if (ssl->cfg.cacert_pem_buf) {
ssl->verify_server = true;
}
+ if (ssl->cfg.clientcert_pem_buf && ssl->cfg.clientkey_pem_buf) {
+ ssl->mutual_authentication = true;
+ }
ssl->cfg.timeout_ms = timeout_ms;
ssl->cfg.non_block = true;
ssl->ssl_initialized = true;
if (ssl->cfg.cacert_pem_buf) {
ssl->verify_server = true;
}
+ if (ssl->cfg.clientcert_pem_buf && ssl->cfg.clientkey_pem_buf) {
+ ssl->mutual_authentication = true;
+ }
ssl->cfg.timeout_ms = timeout_ms;
ssl->ssl_initialized = true;
ssl->tls = esp_tls_conn_new(host, strlen(host), port, &ssl->cfg);
esp_tls_conn_delete(ssl->tls);
ssl->ssl_initialized = false;
ssl->verify_server = false;
+ ssl->mutual_authentication = false;
}
return ret;
}
}
}
+void esp_transport_ssl_set_client_cert_data(esp_transport_handle_t t, const char *data, int len)
+{
+ transport_ssl_t *ssl = esp_transport_get_context_data(t);
+ if (t && ssl) {
+ ssl->cfg.clientcert_pem_buf = (void *)data;
+ ssl->cfg.clientcert_pem_bytes = len + 1;
+ }
+}
+
+void esp_transport_ssl_set_client_key_data(esp_transport_handle_t t, const char *data, int len)
+{
+ transport_ssl_t *ssl = esp_transport_get_context_data(t);
+ if (t && ssl) {
+ ssl->cfg.clientkey_pem_buf = (void *)data;
+ ssl->cfg.clientkey_pem_bytes = len + 1;
+ }
+}
+
esp_transport_handle_t esp_transport_ssl_init()
{
esp_transport_handle_t t = esp_transport_init();