7#ifdef USE_OTA_ENCRYPTION
26#ifdef USE_OTA_PASSWORD
30#ifdef USE_OTA_ENCRYPTION
35#ifdef USE_OTA_PASSWORD
41 static_assert(B,
"set_auth_password() requires the OTA auth path to be compiled. "
42 "Add 'password: \"\"' (empty string) to your 'ota: - platform: esphome' "
43 "config to enable runtime password rotation.");
47#if defined(USE_OTA_ENCRYPTION) && !defined(USE_OTA_ENCRYPTION_FROM_API)
55 void setup()
override;
65#ifdef USE_OTA_PASSWORD
77#ifdef USE_OTA_ENCRYPTION
87 uint8_t
frame_buf[noise::FRAME_HEADER_SIZE + 1 + noise::MAX_HANDSHAKE_SIZE];
107#ifdef USE_OTA_ENCRYPTION
108 if (this->
noise_ !=
nullptr)
115#ifdef USE_OTA_ENCRYPTION
116 if (this->
noise_ !=
nullptr)
122 bool try_read_(
size_t to_read,
const LogString *desc);
123 bool try_write_(
size_t to_write,
const LogString *desc);
125 inline bool would_block_(
int error_code)
const {
return error_code == EAGAIN || error_code == EWOULDBLOCK; }
140 uint8_t error_byte =
static_cast<uint8_t
>(error);
141 this->
client_->write(&error_byte, 1);
146#ifdef USE_OTA_PASSWORD
150#ifdef USE_OTA_ENCRYPTION
151#ifndef USE_OTA_ENCRYPTION_FROM_API
167#ifdef USE_OTA_ENCRYPTION
172 "OTA_BUFFER_SIZE must fit a full encrypted data frame");
174 static constexpr uint8_t
MAGIC_BYTES[5] = {0x6C, 0x26, 0xF7, 0x5C, 0x45};
177#ifdef USE_OTA_PARTITIONS
186#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.
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]
void yield_and_feed_watchdog_()
bool writeall_(const uint8_t *buf, size_t len)
bool try_read_(size_t to_read, const LogString *desc)
bool data_readall_(uint8_t *buf, size_t len)
noise::NoiseContext noise_ctx_
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)
Allocate the session and start the responder handshake.
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
std::unique_ptr< uint8_t[]> auth_buf_
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;...
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_
float get_setup_priority() const override
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)
std::unique_ptr< NoiseSession > noise_
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)
void noise_send_reject_(const LogString *reason)
Best-effort explicit reject frame so the client can log a readable reason.
bool noise_write_byte_(uint8_t byte)
Blocking write of one response byte as an encrypted frame.
uint8_t handshake_buf_[HANDSHAKE_BUF_SIZE]
static constexpr size_t HANDSHAKE_BUF_SIZE
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_()
socket::ListenSocket * server_
void log_remote_closed_(const LogString *during)
std::unique_ptr< socket::Socket > client_
void log_start_(const LogString *phase)
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
uint16_t uint16_t & capacity
NoiseCipherState * recv_cipher
uint8_t frame_buf[noise::FRAME_HEADER_SIZE+1+noise::MAX_HANDSHAKE_SIZE]
NoiseCipherState * send_cipher
noise::NoiseResponderHandshake handshake