mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-03 03:31:41 +03:00
feat: migrates esp_http_client and esp_http_server to PSA APIs
This commit is contained in:
committed by
Mahavir Jain
parent
b5d05d3e7c
commit
fdd5ef561d
@@ -11,7 +11,7 @@
|
||||
#include <sys/random.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_err.h>
|
||||
|
||||
#include <psa/crypto.h>
|
||||
#include <mbedtls/base64.h>
|
||||
#include <mbedtls/error.h>
|
||||
|
||||
@@ -143,17 +143,29 @@ esp_err_t httpd_ws_respond_server_handshake(httpd_req_t *req, const char *suppor
|
||||
|
||||
ESP_LOGD(TAG, LOG_FMT("Server key before encoding: %s"), server_raw_text);
|
||||
|
||||
#if CONFIG_MBEDTLS_SHA1_C || CONFIG_MBEDTLS_HARDWARE_SHA
|
||||
esp_err_t err = httpd_crypto_sha1((const uint8_t *)server_raw_text, strlen(server_raw_text), server_key_hash);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to compute SHA-1 hash");
|
||||
return err;
|
||||
/* Generate SHA-1 hash */
|
||||
psa_hash_operation_t sha1_operation = PSA_HASH_OPERATION_INIT;
|
||||
psa_status_t status = psa_hash_setup(&sha1_operation, PSA_ALG_SHA_1);
|
||||
if (status != PSA_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Failed to setup SHA-1 operation");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
#else
|
||||
ESP_LOGE(TAG, "Please enable CONFIG_MBEDTLS_SHA1_C or CONFIG_MBEDTLS_HARDWARE_SHA to support SHA1 operations");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#endif /* CONFIG_MBEDTLS_SHA1_C || CONFIG_MBEDTLS_HARDWARE_SHA */
|
||||
|
||||
status = psa_hash_update(&sha1_operation, (uint8_t *)server_raw_text, strlen(server_raw_text));
|
||||
if (status != PSA_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Failed to update SHA-1 hash");
|
||||
psa_hash_abort(&sha1_operation);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
size_t hash_length;
|
||||
status = psa_hash_finish(&sha1_operation, server_key_hash, sizeof(server_key_hash), &hash_length);
|
||||
if (status != PSA_SUCCESS || hash_length != sizeof(server_key_hash)) {
|
||||
ESP_LOGE(TAG, "Failed to finish SHA-1 hash");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
/* Encode to Base64 */
|
||||
size_t encoded_len = 0;
|
||||
mbedtls_base64_encode((uint8_t *)server_key_encoded, sizeof(server_key_encoded), &encoded_len,
|
||||
server_key_hash, sizeof(server_key_hash));
|
||||
|
||||
Reference in New Issue
Block a user