Skip to content
Back to skills

Esp32 Tls And Certificates

ASecurity

Use when HTTPS on the ESP32 fails - the handshake times out, memory runs out, the certificate is rejected, or it works with the time unset and fails after. Covers mbedTLS memory, cert bundles, SNI and clock dependency.

  • 16 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 7, 2026
ai-agentsapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 7, 2026

npx -y skills add Esmail-sarhadi/esp32-agent-skills --skill esp32-tls-and-certificates --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Esp32 Tls And Certificates?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Esp32 Tls And Certificates
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/esmail-sarhadi-esp32-tls-and-certificates/badge)](https://www.skillsdirectory.com/skills/esmail-sarhadi-esp32-tls-and-certificates)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: esp32-tls-and-certificates
description: Use when HTTPS on the ESP32 fails - the handshake times out, memory runs out, the certificate is rejected, or it works with the time unset and fails after. Covers mbedTLS memory, cert bundles, SNI and clock dependency.
license: MIT
---

# TLS on ESP32

A TLS handshake is the most memory-hungry thing a small ESP32 does. It needs
about 40 kB of heap for a 2048-bit RSA handshake (more for 4096-bit), and it
needs the clock to be roughly right.

## Memory first

`mbedtls_ssl_handshake` returning `-0x7F00` (ALLOC_FAILED) is not a certificate
problem. Before the handshake:

- Free heap should be at least 50 kB, and the largest free block matters more
  than the total.
- Do not hold a large String of the response body while connecting.
- One TLS connection at a time on a classic ESP32. Two concurrent handshakes
  usually fail.

`CONFIG_MBEDTLS_DYNAMIC_BUFFER` and the `MBEDTLS_SSL_IN_CONTENT_LEN` /
`OUT_CONTENT_LEN` settings trade throughput for memory; 4 kB in and 4 kB out is
enough for most API calls.

## Certificates

Three approaches, in increasing order of maintenance:

1. **Skip verification** (`client.setInsecure()`): works, and is a decision to
   accept any certificate, including an attacker's. Acceptable for a lab.
2. **Pin one CA**: small, and breaks the day the CA rotates its intermediate -
   which happens more often than people expect.
3. **Cert bundle** (`esp_crt_bundle_attach`): the roots of the major CAs,
   ~64 kB of flash, no RAM cost, and it survives rotation. This is the right
   default for a product.

A server whose chain includes an intermediate that is not sent will fail
verification on the ESP32 even though browsers hide it by fetching the
intermediate. Test with `openssl s_client -showcerts`.

## The clock, again

Certificate validity is a date range. At boot the ESP32 clock starts at 1970, so
every certificate is "not yet valid" and the handshake fails with
`MBEDTLS_ERR_X509_CERT_VERIFY_FAILED`. Either start SNTP and wait for a
plausible time before the first HTTPS request, or accept the risk of skipping
time validation - but know which one you did.

## SNI

Servers hosting many domains (Cloudflare, most CDNs) need the hostname in the
handshake. Arduino's `WiFiClientSecure` sets it when you call `connect(host,
port)`. A raw `IPAddress` connect does not, and the server returns the wrong
certificate - which looks like a verification failure on a valid site.

## TLS versions

ESP-IDF 5.x supports TLS 1.3, but it is not the default on every Arduino core.
A server that requires 1.3 (some do now) will fail with a protocol error on an
older core. Check `MBEDTLS_VERSION_STRING` before blaming the certificate.

| Symptom | Usually |
|---|---|
| `-0x7F00` during handshake | not enough heap, or two connections at once |
| certificate verify failed | wrong CA, missing intermediate, or clock at 1970 |
| works at home, fails at the customer | captive portal intercepting, or a proxy |
| handshake takes 8 seconds | RSA 4096, or a slow link - use ECDSA where possible |
| fails only after deep sleep | clock reset, time never re-synced |

Files in this skill

  • LICENSE.txt857 B
  • SKILL.md3.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.