7#ifdef USE_OTA_ENCRYPTION
29#ifdef USE_OTA_PASSWORD
33#ifdef USE_OTA_ENCRYPTION
38#ifdef USE_OTA_PASSWORD
44 static_assert(B,
"set_auth_password() requires the OTA auth path to be compiled. "
45 "Add 'password: \"\"' (empty string) to your 'ota: - platform: esphome' "
46 "config to enable runtime password rotation.");
50#ifdef USE_OTA_ENCRYPTION
58 void setup()
override;
68#ifdef USE_OTA_PASSWORD
80#ifdef USE_OTA_ENCRYPTION
90 uint8_t
frame_buf[noise::FRAME_HEADER_SIZE + 1 + noise::MAX_HANDSHAKE_SIZE];
114#ifdef USE_OTA_ENCRYPTION
115 if (this->
noise_ !=
nullptr)
122#ifdef USE_OTA_ENCRYPTION
123 if (this->
noise_ !=
nullptr)
133#if USE_OTA_VERSION == 2
143#ifdef USE_SOCKET_IMPL_LWIP_TCP
157 inline bool read_size_(uint8_t *buf,
size_t &
size,
const LogString *desc);
161 bool try_read_(
size_t to_read,
const LogString *desc);
162 bool try_write_(
size_t to_write,
const LogString *desc);
164 inline bool would_block_(
int error_code)
const {
return error_code == EAGAIN || error_code == EWOULDBLOCK; }
180 uint8_t error_byte =
static_cast<uint8_t
>(error);
181 this->
client_->write(&error_byte, 1);
186#ifdef USE_OTA_PASSWORD
190#ifdef USE_OTA_ENCRYPTION
192#ifdef USE_OTA_ENCRYPTION_PROVISIONED
209#ifdef USE_OTA_ENCRYPTION
214 "OTA_BUFFER_SIZE must fit a full encrypted data frame");
216#ifdef USE_OTA_DEFLATE
235 static_assert(!ota::OTABackend::supports_compression(),
236 "USE_OTA_DEFLATE is for backends that cannot store a gzip image");
244 static constexpr uint8_t
MAGIC_BYTES[5] = {0x6C, 0x26, 0xF7, 0x5C, 0x45};
247#ifdef USE_OTA_PARTITIONS
257#ifdef USE_OTA_PASSWORD
ESPHomeOTAComponent provides a simple way to integrate Over-the-Air updates into your app using Ardui...
static constexpr size_t OTA_BUFFER_SIZE
bool handle_noise_handshake_()
Drive the non-blocking handshake from loop(); returns true once the transport ciphers are ready.
ssize_t receive_data_(uint8_t *buf, DataTransfer &xfer)
bool would_block_(int error_code) const
uint32_t running_app_offset_
uint8_t handshake_buf_pos_
uint16_t get_port() const
static constexpr size_t SHA256_HEX_SIZE
static constexpr uint8_t MAGIC_BYTES[5]
ota::OTAResponseTypes write_flash_(uint8_t *data, size_t len)
void yield_and_feed_watchdog_()
bool writeall_(const uint8_t *buf, size_t len)
bool try_read_(size_t to_read, const LogString *desc)
static constexpr bool ACK_AFTER_WRITE
static constexpr size_t OTA_INFLATE_WINDOW_SIZE
bool data_readall_(uint8_t *buf, size_t len)
noise::NoiseContext noise_ctx_
void ack_written_(DataTransfer &xfer)
ssize_t noise_decrypt_(uint8_t *buf, size_t len)
Decrypt a ciphertext in place; returns the plaintext size or -1.
bool noise_readall_(uint8_t *buf, size_t len)
Blocking read of one frame whose plaintext must be exactly len bytes (control units are one unit per ...
bool noise_start_session_(uint8_t server_feature_flags)
Start the responder handshake, on the session reserved at offer time.
void set_noise_psk(const uint8_t *psk)
psk points at 32 bytes that live in flash for the life of the program
void set_auth_password(const std::string &password)
ota::OTABackendPtr backend_
bool try_write_(size_t to_write, const LogString *desc)
void dump_config() override
bool noise_try_read_frame_()
Non-blocking read of one handshake frame into the session buffer.
static constexpr size_t NOISE_CLIENT_MAX_PLAINTEXT
bool noise_offered_() const
RAMUniquePtr< NoiseSession > noise_
bool extended_proto_() const
bool handle_write_error_(ssize_t written, const LogString *desc)
ssize_t noise_read_frame_blocking_(uint8_t *buf, size_t min_ciphertext, size_t max_ciphertext)
Blocking read of one frame whose ciphertext size must be within the given bounds, decrypted in place;...
void send_chunk_acks_(DataTransfer &xfer)
bool data_write_byte_(uint8_t byte)
size_t noise_frame_payload_len_(const uint8_t *header, size_t min_len, size_t max_len)
Payload length from a frame header, or 0 (logged) when the indicator or the length is out of range.
void log_auth_warning_(const LogString *msg)
uint32_t client_connect_time_
RAMUniquePtr< InflateSession > inflate_
float get_setup_priority() const override
bool client_left_before_start_()
void send_error_and_cleanup_(ota::OTAResponseTypes error)
bool handle_read_error_(ssize_t read, const LogString *desc)
ssize_t noise_read_data_(uint8_t *buf, size_t capacity)
Blocking read of one data-phase frame, decrypted in place; returns the plaintext size,...
void log_read_error_(const LogString *what)
bool readall_(uint8_t *buf, size_t len)
void set_port(uint16_t port)
Manually set the port OTA should listen on.
void set_auth_password(const std::string &)
bool write_byte_(uint8_t byte)
RAMUniquePtr< uint8_t[]> auth_buf_
void noise_send_reject_(const LogString *reason)
Best-effort explicit reject frame so the client can log a readable reason.
RAMUniquePtr< noise::psk_t > saved_psk_
bool noise_write_byte_(uint8_t byte)
Blocking write of one response byte as an encrypted frame.
void ack_received_(DataTransfer &xfer)
uint8_t handshake_buf_[HANDSHAKE_BUF_SIZE]
static constexpr size_t HANDSHAKE_BUF_SIZE
ota::OTAResponseTypes inflate_data_(uint8_t *in, size_t image_size, DataTransfer &xfer)
const noise::NoiseContext & noise_context_() const
void server_failed_(const LogString *msg)
void transition_ota_state_(OTAState next_state)
bool noise_try_write_frame_()
Non-blocking write of the pending session-buffer frame.
void cleanup_connection_()
bool read_size_(uint8_t *buf, size_t &size, const LogString *desc)
void noise_reserve_session_()
socket::ListenSocket * server_
void log_remote_closed_(const LogString *during)
std::unique_ptr< socket::Socket > client_
void log_start_(const LogString *phase)
ota::OTAResponseTypes inflate_flush_(InflateSession &session)
void log_socket_error_(const LogString *msg)
void set_psk(const uint8_t *psk)
psk points at 32 bytes that outlive the context (PROGMEM or caller owned RAM); nullptr means no key.
Sans-IO responder side of a Noise_NNpsk0_25519_ChaChaPoly_SHA256 handshake.
decltype(make_ota_backend()) OTABackendPtr
std::unique_ptr< T, RAMDeleter< T > > RAMUniquePtr
unique_ptr over RAMAllocator storage
uint16_t uint16_t & capacity
ESPHomeOTAComponent * self
uint8_t window[OTA_INFLATE_WINDOW_SIZE]
ota::OTAResponseTypes error
NoiseCipherState * recv_cipher
uint8_t frame_buf[noise::FRAME_HEADER_SIZE+1+noise::MAX_HANDSHAKE_SIZE]
NoiseCipherState * send_cipher
noise::NoiseResponderHandshake handshake