Merge pull request #1005 from mc-hamster/master

Fix for "Creating SSL certificate" screen when there's no display
1.2-legacy
Jm Casler 2021-12-18 14:49:16 -05:00 zatwierdzone przez GitHub
commit 4a053801ce
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 39 dodań i 52 usunięć

Wyświetl plik

@ -40,6 +40,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NO_ESP32
#include "mesh/http/WiFiAPClient.h"
#include "esp_task_wdt.h"
#endif
using namespace meshtastic; /** @todo remove */
@ -155,6 +156,11 @@ static void drawSSLScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16
display->setFont(FONT_SMALL);
display->drawString(64 + x, y, "Creating SSL certificate");
#ifndef NO_ESP32
yield();
esp_task_wdt_reset();
#endif
display->setFont(FONT_SMALL);
if ((millis() / 1000) % 2) {
display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait . . .");
@ -697,6 +703,7 @@ void _screen_header()
Screen::Screen(uint8_t address, int sda, int scl) : OSThread("Screen"), cmdQueue(32), dispdev(address, sda, scl), ui(&dispdev)
{
address_found = address;
cmdQueue.setReader(this);
}
@ -934,10 +941,12 @@ void Screen::drawDebugInfoWiFiTrampoline(OLEDDisplay *display, OLEDDisplayUiStat
* it is expected that this will be used during the boot phase */
void Screen::setSSLFrames()
{
DEBUG_MSG("showing SSL frames\n");
static FrameCallback sslFrames[] = {drawSSLScreen};
ui.setFrames(sslFrames, 1);
ui.update();
if (address_found) {
// DEBUG_MSG("showing SSL frames\n");
static FrameCallback sslFrames[] = {drawSSLScreen};
ui.setFrames(sslFrames, 1);
ui.update();
}
}
// restore our regular frame list

Wyświetl plik

@ -97,6 +97,8 @@ class Screen : public concurrency::OSThread
Screen(const Screen &) = delete;
Screen &operator=(const Screen &) = delete;
uint8_t address_found;
/// Initializes the UI, turns on the display, starts showing boot screen.
//
// Not thread safe - must be called before any other methods are called.

Wyświetl plik

@ -6,6 +6,8 @@
#include <HTTPMultipartBodyParser.hpp>
#include <HTTPURLEncodedBodyParser.hpp>
#include "sleep.h"
#include "graphics/Screen.h"
#include <WebServer.h>
#include <WiFi.h>
@ -79,13 +81,13 @@ static void taskCreateCert(void *parameter)
{
prefs.begin("MeshtasticHTTPS", false);
// Delete the saved certs (used in debugging)
#if 0
DEBUG_MSG("Deleting any saved SSL keys ...\n");
// prefs.clear();
prefs.remove("PK");
prefs.remove("cert");
// Delete the saved certs (used in debugging)
DEBUG_MSG("Deleting any saved SSL keys ...\n");
// prefs.clear();
prefs.remove("PK");
prefs.remove("cert");
#endif
@ -156,6 +158,7 @@ static void taskCreateCert(void *parameter)
void createSSLCert()
{
bool runLoop = false;
if (isWifiAvailable() && !isCertReady) {
// Create a new process just to handle creating the cert.
@ -163,21 +166,28 @@ void createSSLCert()
// jm@casler.org (Oct 2020)
xTaskCreate(taskCreateCert, /* Task function. */
"createCert", /* String with name of task. */
16384, /* Stack size in bytes. */
//16384, /* Stack size in bytes. */
8192, /* Stack size in bytes. */
NULL, /* Parameter passed as input of the task */
16, /* Priority of the task. */
NULL); /* Task handle. */
DEBUG_MSG("Waiting for SSL Cert to be generated.\n");
int seconds = 0;
while (!isCertReady) {
DEBUG_MSG(".");
delay(1000);
yield();
esp_task_wdt_reset();
seconds++;
if ((seconds == 3) && screen) {
screen->setSSLFrames();
if ((millis() / 500) % 2) {
if (runLoop) {
DEBUG_MSG(".");
yield();
esp_task_wdt_reset();
if (millis() / 1000 >= 3) {
screen->setSSLFrames();
}
}
runLoop = false;
} else {
runLoop = true;
}
}
DEBUG_MSG("SSL Cert Ready!\n");
@ -201,40 +211,6 @@ void initWebServer()
{
DEBUG_MSG("Initializing Web Server ...\n");
#if 0
// this seems to be a copypaste dup of taskCreateCert
prefs.begin("MeshtasticHTTPS", false);
size_t pkLen = prefs.getBytesLength("PK");
size_t certLen = prefs.getBytesLength("cert");
DEBUG_MSG("Checking if we have a previously saved SSL Certificate.\n");
if (pkLen && certLen) {
uint8_t *pkBuffer = new uint8_t[pkLen];
prefs.getBytes("PK", pkBuffer, pkLen);
uint8_t *certBuffer = new uint8_t[certLen];
prefs.getBytes("cert", certBuffer, certLen);
cert = new SSLCert(certBuffer, certLen, pkBuffer, pkLen);
DEBUG_MSG("Retrieved Private Key: %d Bytes\n", cert->getPKLength());
// DEBUG_MSG("Retrieved Private Key: " + String(cert->getPKLength()) + " Bytes");
// for (int i = 0; i < cert->getPKLength(); i++)
// Serial.print(cert->getPKData()[i], HEX);
// Serial.println();
DEBUG_MSG("Retrieved Certificate: %d Bytes\n", cert->getCertLength());
// for (int i = 0; i < cert->getCertLength(); i++)
// Serial.print(cert->getCertData()[i], HEX);
// Serial.println();
} else {
DEBUG_MSG("Web Server started without SSL keys! How did this happen?\n");
}
#endif
// We can now use the new certificate to setup our server as usual.
secureServer = new HTTPSServer(cert);
insecureServer = new HTTPServer();