circuitpython: certificate chain verification bug in esp-idf
the following request works OK with and ESP32 with the NINA firmware, but not with the esp32s2 native wifi
response = requests.get("https://api.thingspeak.com/channels/1417/feeds.json?results=1")
fails with
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "wifi_cheer.py", line 39, in <module>
File "adafruit_requests.py", line 507, in get
File "adafruit_requests.py", line 456, in request
File "adafruit_requests.py", line 405, in _get_socket
File "adafruit_requests.py", line 401, in _get_socket
OSError: Failed SSL handshake
>>>
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (9 by maintainers)
Commits related to this issue
- esp32s2: Update esp-idf submodule to include fix for #3424 This re-points the submodule to my personal fork of esp-idf. Users may need to `git submodule sync` in their existing trees when this change... — committed to jepler/circuitpython by jepler 4 years ago
- Merge pull request #3691 from jepler/issue-3424 esp32s2: Update esp-idf submodule to include fix for #3424 — committed to adafruit/circuitpython by tannewt 4 years ago
Hi, I think I’m still getting this bug today, even after updating my board (Feather S2) to the newest firmware from S3 and the 20201117 library bundle. Issue happens even if I use the firmware directly referenced in the commit for this fix (f8eed1f).
Interestingly, the examples from this bug (thingspeak.com, io.adafruit.com) do appear to work properly now, but my own domain does not. I’m suspecting that it’s an issue with my SSL certificate chain based on the SSL Labs report, but I’m not entirely sure there’s anything I can do on my end to fix it.
My code:
Result:
Edit: I updated my cert to a LetsEncrypt cert and it now works fine. I’m assuming my SSL cert provider was the cause of the issue and won’t be using them again. Might still be worth looking into as a potential blocker for others? FWIW, my cert was a PositiveSSL cert purchased from namecheap.com (issuer was sectigo).
@jepler Want to switch circuitpython to your IDF branch until it is integrated upstream? I think this is the right fix.
This looks site-specific, so I think cert-related. I had never encountered the SSL handshake issue with my own server (HTTPS/TLS), but I can replicate with the link above. Doesn’t matter if the RTC is 2000 or 2020.
I ran that python script from this folder circuitpython/ports/esp32s2/esp-idf/components/mbedtls/esp_crt_bundle
And then you end up with a new x509_crt_bundle
Slowly trying to make some sense of this the way certificates are configured in the sdconfig is quite different for the ESP32S2 https://github.com/adafruit/circuitpython/blob/main/ports/esp32s2/esp-idf-config/sdkconfig.defaults#L548 vs NINA https://github.com/adafruit/nina-fw/blob/master/sdkconfig#L563
It is also not clear to me how to update the certificates used by the ids in the esp32s2 in the Docs it says the certificates used are quite old - Jan 2019 – and the ones in the NINA build are much newer
It also indicates that one can specify a file when building so I think that is the route to examine …
These are the API docs where I would start: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/esp_crt_bundle.html
@brentru might have experience with it for nina.