From 5ec6577b5ac6acd32e03651cece9ca48cfc29a5e Mon Sep 17 00:00:00 2001 From: leukipp Date: Fri, 19 Sep 2025 15:52:09 +0200 Subject: [PATCH] fix: option to ignore certificate errors #76 --- js/integration.js | 5 +++-- js/webview.js | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/js/integration.js b/js/integration.js index a627a9f..f7ed460 100644 --- a/js/integration.js +++ b/js/integration.js @@ -49,8 +49,9 @@ const init = async () => { }; // Connection settings - const options = user === null || password === null ? null : { username: user, password: password }; - const masked = password === null ? "null" : "*".repeat(password.length); + const masked = password === null ? null : "*".repeat(password.length); + const options = user === null || password === null ? {} : { username: user, password: password }; + options.rejectUnauthorized = !("ignore_certificate_errors" in ARGS); console.log("MQTT Connecting:", `${user}:${masked}@${url.toString()}`); INTEGRATION.client = mqtt.connect(url.toString(), options); diff --git a/js/webview.js b/js/webview.js index 3e122d5..89d8f16 100644 --- a/js/webview.js +++ b/js/webview.js @@ -1,5 +1,6 @@ const path = require("path"); const axios = require("axios"); +const https = require("https"); const hardware = require("./hardware"); const integration = require("./integration"); const { app, nativeTheme, globalShortcut, ipcMain, session, BaseWindow, WebContentsView } = require("electron"); @@ -845,7 +846,8 @@ const onlineStatus = (url, interval = 1000, timeout = 60000) => { const elapsed = Date.now() - start; try { if (!url.startsWith("data:")) { - await axios.get(url, { timeout: 10000 }); + const agent = new https.Agent({ rejectUnauthorized: !("ignore_certificate_errors" in ARGS) }); + await axios.get(url, { httpsAgent: agent, timeout: 10000 }); } resolve(true); } catch (error) { @@ -853,6 +855,9 @@ const onlineStatus = (url, interval = 1000, timeout = 60000) => { console.warn(`Checking Connection: ${url}`, error.message); } if (elapsed >= timeout) { + if (error.message?.includes("certificate")) { + console.error("Certificate Error: See https://github.com/leukipp/touchkio/issues/76"); + } resolve(false); } else { setTimeout(check, interval);