Skip to content

Commit aa84abe

Browse files
schiermiamandel
authored andcommitted
Use Mozilla CA certificate store
1 parent 292e14d commit aa84abe

File tree

7 files changed

+18
-255
lines changed

7 files changed

+18
-255
lines changed

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ monitor_speed = 115200
4646
; with it. If uploads fail for you, comment out the following line:
4747
upload_speed = 921600
4848
board_build.partitions = src/sd-partition-table.csv
49+
board_build.embed_txtfiles = src/truststore/x509_crt_bundle
4950
lib_deps =
5051
adafruit/Adafruit BusIO @ ^1.13.1
5152
; https://arduinojson.org/v6/api/

src/Firmware.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
#include <SD.h>
2828
#include <Update.h>
2929
#include <esp_ota_ops.h>
30-
#include "utils/cacerts.h"
30+
31+
// https://docs.platformio.org/en/latest/platforms/espressif32.html#embedding-binary-data
32+
extern const uint8_t x509_crt_bundle_start[] asm("_binary_src_truststore_x509_crt_bundle_start");
3133

3234
static const String FLASH_APP_FILENAME("/sdflash/app.bin");
3335
static const String OPEN_BIKE_SENSOR_FLASH_APP_PROJECT_NAME("OpenBikeSensorFlash");
@@ -37,7 +39,7 @@ static const int SHA256_HASH_LEN = 32;
3739
// todo: error handling
3840
void Firmware::downloadToSd(String url, String filename, bool unsafe) {
3941
WiFiClientSecure client;
40-
if (!unsafe) client.setCACert(trustedRootCACertificates);
42+
if (!unsafe) client.setCACertBundle(x509_crt_bundle_start);
4143
else client.setInsecure();
4244
HTTPClient http;
4345
http.setUserAgent(mUserAgent);
@@ -63,8 +65,8 @@ bool Firmware::downloadToFlash(String url,
6365
bool unsafe) {
6466
bool success = false;
6567
WiFiClientSecure client;
66-
if (!unsafe) client.setCACert(trustedRootCACertificates);
67-
if (unsafe) client.setInsecure();
68+
if (!unsafe) client.setCACertBundle(x509_crt_bundle_start);
69+
else client.setInsecure();
6870
HTTPClient http;
6971
http.setUserAgent(mUserAgent);
7072
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);

src/truststore/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Full TLS Truststore
2+
3+
## Generate / Update
4+
5+
1. curl --remote-name https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/gen_crt_bundle.py
6+
1. curl --remote-name https://curl.se/ca/cacert.pem
7+
1. python3 gen_crt_bundle.py --input cacert.pem

src/truststore/x509_crt_bundle

65.9 KB
Binary file not shown.

src/uploader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@
2525

2626
#include "globals.h"
2727
#include "utils/multipart.h"
28-
#include "utils/cacerts.h"
2928
#include "utils/timeutils.h"
3029
#include "writer.h"
3130

31+
// https://docs.platformio.org/en/latest/platforms/espressif32.html#embedding-binary-data
32+
extern const uint8_t x509_crt_bundle_start[] asm("_binary_src_truststore_x509_crt_bundle_start");
33+
3234
static char const *const HTTP_LOCATION_HEADER = "location";
3335

3436
Uploader::Uploader(String portalUrl, String userToken) :
3537
mPortalUrl(std::move(portalUrl)),
3638
mPortalUserToken(std::move(userToken)) {
3739
TimeUtils::setClockByNtpAndWait();
38-
mWiFiClient.setCACert(trustedRootCACertificates);
40+
mWiFiClient.setCACertBundle(x509_crt_bundle_start);
3941
}
4042

4143
/* Upload file as track data to "The Portal" as multipart form data.

src/utils/cacerts.cpp

Lines changed: 0 additions & 219 deletions
This file was deleted.

src/utils/cacerts.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)