#include "ota_device.h" #include #include "ota_public_key.h" namespace roro { EcdsaVerifier::EcdsaVerifier() { mbedtls_pk_init(&key_); // PEM parsing wants the terminating NUL counted in the length. ready_ = mbedtls_pk_parse_public_key(&key_, reinterpret_cast(kOtaPublicKeyPem), std::strlen(kOtaPublicKeyPem) + 1) == 0; } EcdsaVerifier::~EcdsaVerifier() { mbedtls_pk_free(&key_); } bool EcdsaVerifier::verify(const uint8_t digest[32], const uint8_t* signature, size_t len) { return ready_ && mbedtls_pk_verify(&key_, MBEDTLS_MD_SHA256, digest, 32, signature, len) == 0; } bool EspOtaSink::begin(size_t imageSize) { if (!slot_) return false; open_ = esp_ota_begin(slot_, imageSize, &handle_) == ESP_OK; return open_; } bool EspOtaSink::write(const uint8_t* data, size_t len) { return open_ && esp_ota_write(handle_, data, len) == ESP_OK; } bool EspOtaSink::finish() { if (!open_) return false; open_ = false; // esp_ota_end() also validates the image structure (segments, checksum) for this chip. return esp_ota_end(handle_) == ESP_OK && esp_ota_set_boot_partition(slot_) == ESP_OK; } void EspOtaSink::abort() { if (open_) esp_ota_abort(handle_); open_ = false; } } // namespace roro