Skip to content

Commit 7fe212c

Browse files
authored
increase certificate size if psram is available (#741)
1 parent 213e0e8 commit 7fe212c

File tree

6 files changed

+1016
-1028
lines changed

6 files changed

+1016
-1028
lines changed

clion/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ set(SRCFILES
6161
../src/SerialReader.cpp
6262
../src/util/NukiHelper.cpp
6363
../src/util/NukiOpenerHelper.cpp
64+
../src/util/CertUtil.h
6465
)
6566

6667
file(GLOB_RECURSE SRCFILESREC

src/PreferencesKeys.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "FS.h"
77
#include "SPIFFS.h"
88
#include "RestartReason.h"
9+
#include "util/CertUtil.h"
910

1011
#ifndef CONFIG_IDF_TARGET_ESP32H2
1112
#include <WiFi.h>
@@ -431,13 +432,22 @@ inline void initPreferences(Preferences* preferences)
431432
{
432433
Log->println("Migration 9.07");
433434

434-
char ca[2200] = {0};
435-
char cert[2200] = {0};
436-
char key[2200] = {0};
435+
int size = certSize();
437436

438-
size_t caLength = preferences->getString(preference_mqtt_ca, ca, 2200);
439-
size_t crtLength = preferences->getString(preference_mqtt_crt, cert, 2200);
440-
size_t keyLength = preferences->getString(preference_mqtt_key, key, 2200);
437+
char ca[size];
438+
char cert[size];
439+
char key[size];
440+
441+
for (int i = 0; i < certSize(); i++)
442+
{
443+
ca[i] = 0;
444+
cert[i] = 0;
445+
key[i] = 0;
446+
}
447+
448+
size_t caLength = preferences->getString(preference_mqtt_ca, ca, size);
449+
size_t crtLength = preferences->getString(preference_mqtt_crt, cert, size);
450+
size_t keyLength = preferences->getString(preference_mqtt_key, key, size);
441451

442452
if (caLength > 1)
443453
{

src/WebCfgServer.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "PreferencesKeys.h"
44
#include "Logger.h"
55
#include "RestartReason.h"
6+
#include "util/CertUtil.h"
67
#include <esp_task_wdt.h>
78
#include "FS.h"
89
#include "SPIFFS.h"
@@ -5585,14 +5586,14 @@ esp_err_t WebCfgServer::buildMqttSSLConfigHtml(PsychicRequest *request, PsychicR
55855586
file.close();
55865587
ca[filesize] = '\0';
55875588

5588-
printTextarea(&response, "MQTTCA", "MQTT SSL CA Certificate", "*", 2200, true, true);
5589+
printTextarea(&response, "MQTTCA", "MQTT SSL CA Certificate", "*", certSize(), true, true);
55895590
found = true;
55905591
}
55915592
}
55925593

55935594
if (!found)
55945595
{
5595-
printTextarea(&response, "MQTTCA", "MQTT SSL CA Certificate", "", 2200, true, true);
5596+
printTextarea(&response, "MQTTCA", "MQTT SSL CA Certificate", "", certSize(), true, true);
55965597
}
55975598
}
55985599
else if (type == 1)
@@ -5620,14 +5621,14 @@ esp_err_t WebCfgServer::buildMqttSSLConfigHtml(PsychicRequest *request, PsychicR
56205621
file.close();
56215622
cert[filesize] = '\0';
56225623

5623-
printTextarea(&response, "MQTTCRT", "MQTT SSL Client Certificate", "*", 2200, true, true);
5624+
printTextarea(&response, "MQTTCRT", "MQTT SSL Client Certificate", "*", certSize(), true, true);
56245625
found = true;
56255626
}
56265627
}
56275628

56285629
if (!found)
56295630
{
5630-
printTextarea(&response, "MQTTCRT", "MQTT SSL Client Certificate", "", 2200, true, true);
5631+
printTextarea(&response, "MQTTCRT", "MQTT SSL Client Certificate", "", certSize(), true, true);
56315632
}
56325633
}
56335634
else
@@ -5655,14 +5656,14 @@ esp_err_t WebCfgServer::buildMqttSSLConfigHtml(PsychicRequest *request, PsychicR
56555656
file.close();
56565657
key[filesize] = '\0';
56575658

5658-
printTextarea(&response, "MQTTKEY", "MQTT SSL Client Key", "*", 2200, true, true);
5659+
printTextarea(&response, "MQTTKEY", "MQTT SSL Client Key", "*", certSize(), true, true);
56595660
found = true;
56605661
}
56615662
}
56625663

56635664
if (!found)
56645665
{
5665-
printTextarea(&response, "MQTTKEY", "MQTT SSL Client Key", "", 2200, true, true);
5666+
printTextarea(&response, "MQTTKEY", "MQTT SSL Client Key", "", certSize(), true, true);
56665667
}
56675668
}
56685669
response.print("</table>");
@@ -5744,14 +5745,14 @@ esp_err_t WebCfgServer::buildHttpSSLConfigHtml(PsychicRequest *request, PsychicR
57445745
file.close();
57455746
key[filesize] = '\0';
57465747

5747-
printTextarea(&response, "HTTPKEY", "HTTP SSL Key", "*", 2200, true, true);
5748+
printTextarea(&response, "HTTPKEY", "HTTP SSL Key", "*", certSize(), true, true);
57485749
found = true;
57495750
}
57505751
}
57515752

57525753
if (!found)
57535754
{
5754-
printTextarea(&response, "HTTPKEY", "HTTP SSL Key", "", 2200, true, true);
5755+
printTextarea(&response, "HTTPKEY", "HTTP SSL Key", "", certSize(), true, true);
57555756
}
57565757
}
57575758
else

src/util/CertUtil.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#if defined(CONFIG_SOC_SPIRAM_SUPPORTED) && defined(CONFIG_SPIRAM)
4+
#include "esp_psram.h"
5+
#endif
6+
7+
inline int certSize()
8+
{
9+
#if defined(CONFIG_SOC_SPIRAM_SUPPORTED) && defined(CONFIG_SPIRAM)
10+
if(esp_psram_get_size() > 0)
11+
{
12+
return 8000;
13+
}
14+
return 2200;
15+
#endif
16+
17+
return 2200;
18+
}

0 commit comments

Comments
 (0)