Skip to content

Commit 616727a

Browse files
Refactor tilefetcher for https (#126)
1 parent b639c4d commit 616727a

File tree

6 files changed

+283
-92
lines changed

6 files changed

+283
-92
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ OSM tiles are quite large at 128kB or insane large at 512kB per tile, so psram i
2424
You can switch provider and tile format at runtime, or set up a different default tile provider if you want.
2525
This library can do it all and is very easy to configure and use.
2626

27+
### TLS validation note
28+
29+
This project currently uses `setInsecure()` for `WiFiClientSecure` connections, which disables certificate validation.
30+
31+
- Risk: Without TLS validation, responses could in theory be intercepted or altered.
32+
This matters most if requests carry secrets (e.g. API keys).
33+
34+
- Practical impact: Standard OpenStreetMap tile servers do not require API keys or credentials.
35+
In this case, the main risk is limited to someone tampering with map images.
36+
37+
- Benefit: Simplifies setup and supports multiple tile providers without needing to manage CA certificates.
38+
2739
## How to use
2840

2941
This library is **PlatformIO only** due to use of modern C++ features. The Arduino IDE is **not** supported.

src/OpenStreetMap-esp32.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void OpenStreetMap::updateCache(const tileList &requiredTiles, uint8_t zoom, Til
205205
if (!jobs.empty())
206206
{
207207
runJobs(jobs);
208-
log_d("Finished %i jobs in %lu ms - %i ms/job", jobs.size(), millis() - startMS, (millis() - startMS) / jobs.size());
208+
log_i("Finished %i jobs in %lu ms - %i ms/job", jobs.size(), millis() - startMS, (millis() - startMS) / jobs.size());
209209
}
210210
}
211211

@@ -360,17 +360,26 @@ void OpenStreetMap::PNGDraw(PNGDRAW *pDraw)
360360

361361
bool OpenStreetMap::fetchTile(ReusableTileFetcher &fetcher, CachedTile &tile, uint32_t x, uint32_t y, uint8_t zoom, String &result, unsigned long timeout)
362362
{
363-
String url = currentProvider->urlTemplate;
364-
url.replace("{x}", String(x));
365-
url.replace("{y}", String(y));
366-
url.replace("{z}", String(zoom));
367-
if (currentProvider->requiresApiKey && strstr(url.c_str(), "{apiKey}"))
368-
url.replace("{apiKey}", currentProvider->apiKey);
363+
char url[256];
364+
if (currentProvider->requiresApiKey)
365+
{
366+
snprintf(url, sizeof(url),
367+
currentProvider->urlTemplate,
368+
zoom, x, y, currentProvider->apiKey);
369+
}
370+
else
371+
{
372+
snprintf(url, sizeof(url),
373+
currentProvider->urlTemplate,
374+
zoom, x, y);
375+
}
369376

370377
MemoryBuffer buffer = fetcher.fetchToBuffer(url, result, timeout);
371378
if (!buffer.isAllocated())
372379
return false;
373380

381+
[[maybe_unused]] const unsigned long startMS = millis();
382+
374383
PNG *png = getPNGCurrentCore();
375384
const int16_t rc = png->openRAM(buffer.get(), buffer.size(), PNGDraw);
376385
if (rc != PNG_SUCCESS)
@@ -390,10 +399,12 @@ bool OpenStreetMap::fetchTile(ReusableTileFetcher &fetcher, CachedTile &tile, ui
390399
const int decodeResult = png->decode(0, PNG_FAST_PALETTE);
391400
if (decodeResult != PNG_SUCCESS)
392401
{
393-
result = "Decoding " + url + " failed with code: " + String(decodeResult);
402+
result = "Decoding " + String(url) + " failed with code: " + String(decodeResult);
394403
return false;
395404
}
396405

406+
log_d("decoding %s took %lu ms on core %i", url, millis() - startMS, xPortGetCoreID());
407+
397408
tile.x = x;
398409
tile.y = y;
399410
tile.z = zoom;

src/OpenStreetMap-esp32.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
constexpr uint16_t OSM_BGCOLOR = lgfx::color565(32, 32, 128);
4343
constexpr UBaseType_t OSM_TASK_PRIORITY = 1;
44-
constexpr uint32_t OSM_TASK_STACKSIZE = 5120;
44+
constexpr uint32_t OSM_TASK_STACKSIZE = 6144;
4545
constexpr uint32_t OSM_JOB_QUEUE_SIZE = 50;
4646
constexpr bool OSM_FORCE_SINGLECORE = false;
4747
constexpr int OSM_SINGLECORE_NUMBER = 1;

0 commit comments

Comments
 (0)