Assignment 1: Establish and verify a TLS connection#
In this assignment, you will run the ESP-IDF https_mbedtls example on the ESP32-S31-Function-CoreBoard-1: configure trust anchors, complete a TLS handshake to a public HTTPS server, and run controlled tests that should fail verification. Read Lecture 1 first for the threat model, API flow, and menuconfig paths.
Before you begin#
Tools: you can follow every assignment from the command line (CLI) or from the CLion IDE.
Prepared project (recommended): use the complete Assignment 1 project from the workshop project setup. The steps below explain the supplied implementation and its verification.
For the manual cumulative route, start from $IDF_PATH/examples/protocols/https_mbedtls and carry the same project through later assignments.
cd assignment-1
idf.py --preview set-target esp32s31Run this from the code-examples directory created during workshop setup. For the manual route, replace assignment-1 with $IDF_PATH/examples/protocols/https_mbedtls.
Replace PORT in the commands below with your serial port.
- Follow the JetBrains ESP-IDF setup instructions to configure a CLion toolchain with the ESP-IDF environment.
- Select File → Open and open the
assignment-1project directory. For the manual route, open$IDF_PATH/examples/protocols/https_mbedtls. - Open View → Tool Windows → Terminal and run:
idf.py --preview set-target esp32s31Reload the CMake project if CLion prompts you.
Network: a Wi-Fi access point with internet access and outbound TCP port 443. The example connects to www.howsmyssl.com.
Step 1: Configure the trust anchor#
Goal: enable the embedded CA bundle used by esp_crt_bundle_attach() (see Trust anchors and the certificate bundle in Lecture 1).
Open the project configuration:
idf.py menuconfigOpen View → Tool Windows → Terminal and run:
idf.py menuconfigJetBrains documents menuconfig as a terminal-based step in the CLion ESP-IDF workflow.
Then:
- Open Component config → mbedTLS → Certificate Bundle.
- Enable Certificate Bundle (CONFIG_MBEDTLS_CERTIFICATE_BUNDLE).
- Leave the default filter list bundle unless your instructor asks for the full Mozilla set (larger binary, broader coverage).
- (Optional, for Step 3 untrusted-server tests) Set Custom Certificate Bundle Path to a folder with a lab CA PEM file: CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE_PATH. Use
.pemor.derextensions only, as documented in ESP x509 Certificate Bundle. - Open Serial flasher config → Flash size and select 4 MB.
- Open Partition Table and select Single factory app (large), no OTA. This gives the application a 1.5 MB partition instead of the default 1 MB partition.
Save the configuration. Add these settings to sdkconfig.defaults in the project root so they survive a clean configuration:
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=yThen build the project:
idf.py buildapp configuration in the configuration switcher, then click Build (the hammer icon). See Build the project.Confirm that the build reports the application fits in the 1.5 MB factory partition.
Step 2: Connect with server authentication#
Goal: bring up the network and complete one successful HTTPS GET (see Network setup and Reference example architecture).
- In the project configuration, open Example Connection Configuration.
- Under Connect using, select Wi-Fi. Set the lab SSID and password (see protocols README).
- Build, flash, and open the monitor:
idf.py -p PORT flash monitorTo quit the monitor, press Ctrl+].
- If the serial port is not detected, add
ESPPORTwith your port as an environment variable under Settings → Build, Execution, Deployment → CMake, then reload the project. - Select the generated
flashconfiguration and click Build. - Select the generated
monitorconfiguration and click Build to open the serial output.
Success criteria (order may vary slightly):
example_connectreports an IPv4 address on Wi-Fi- Log lines similar to:
Attaching the certificate bundle...,Performing the SSL/TLS handshake... esp-x509-crt-bundle: Certificate validatedCertificate verified.- A cipher suite line, for example
Cipher suite is TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 - HTTP response body containing JSON from howsmyssl (TLS version and cipher list)
Capture a screenshot or log excerpt for your workshop notes. This is useful test evidence for protection in transit (see CRA relevance in Lecture 1).
Step 3: Test certificate validation#
Goal: confirm that verification fails closed when trust or hostname is wrong (see Hostname and certificate verification).
Revert to a known-good tree or git stash between tests. Rebuild and flash after each change.
| Test | Change | Expected result |
|---|---|---|
| Wrong hostname | In main/https_mbedtls_example_main.c, call mbedtls_ssl_set_hostname(&ssl, "invalid.example.com") while still connecting to www.howsmyssl.com, or mismatch WEB_SERVER vs the cert name | Non-zero verify flags; Failed to verify peer certificate! and verification info in the log |
| Untrusted server | Point WEB_SERVER / connect target at an HTTPS host that uses a self-signed or private-CA certificate, without adding that CA to the bundle | Handshake failure or verify failure; connection must not treat the peer as trusted |
| Invalid lifetime (optional) | With SNTP configured so wall time is correct, use an instructor-provided expired server cert or test endpoint | Verification failure related to certificate dates |
Do not disable MBEDTLS_SSL_VERIFY_REQUIRED or set authmode to VERIFY_NONE in production firmware. Use misconfiguration only on lab builds to observe failures.
Document each test: what you changed, log output, and whether the device continued to reject the bad case after reboot.
Step 4: Add mutual TLS (optional)#
The stock https_mbedtls example does not implement mTLS. This step is optional.
If your instructor assigns it:
- Read One-way TLS vs mutual TLS in Lecture 1.
- Follow ESP-IDF guidance for client certificates (for example ESP-TLS or mbedTLS
mbedtls_ssl_conf_own_certwith PEM buffers embedded at build time). - Use demonstration client cert and key from your instructor. Store keys in encrypted NVS in real products (Lecture 2).
What you learned#
You should now be able to:
- Enable the ESP-IDF certificate bundle and attach it with
esp_crt_bundle_attach() - Run https_mbedtls on ESP32-S31 over Wi-Fi via
example_connect() - Interpret success logs (
Certificate validated, cipher suite, HTTP JSON response) - Trigger and recognize verification failures (hostname, untrusted CA, optional expiry)
- Describe how monitor logs and test notes support a product trust store policy and CRA-oriented test evidence
Closing demo: TLS power consumption#
After you finish the TLS exercises, the instructor will demonstrate TLS power consumption on the ESP32-S31-Function-CoreBoard-1 using a Qoitech Otii Ace Pro Power Profiler. You will observe the supply current during Wi-Fi startup and the TLS handshake while comparing plain HTTP, a full TLS handshake, and a resumed TLS session. No student wiring is required.
The measurements, results, and instructions for exploring the recordings are available in Power consumption measurement.
