From 3e7ea851060ab8569df16ed45f041c478316d82a Mon Sep 17 00:00:00 2001 From: Robin Davies Date: Sat, 7 Sep 2024 03:10:10 +0100 Subject: [PATCH] Fixups to initial Config --- .vscode/launch.json | 23 +++- .../src/include/WifiDirectConfigSettings.hpp | 2 +- config/{updatekey.gpg => updatekey.asc} | 0 config/updatekey2.asc | Bin 0 -> 1745 bytes react/src/PiPedalModel.tsx | 2 +- react/src/PiPedalSocket.tsx | 101 +++++++++--------- src/ConfigMain.cpp | 31 ++++-- src/SetWifiConfig.cpp | 7 ++ src/Updater.cpp | 9 +- src/UpdaterSecurity.hpp | 7 ++ src/WebServerConfig.cpp | 1 - 11 files changed, 111 insertions(+), 72 deletions(-) rename config/{updatekey.gpg => updatekey.asc} (100%) create mode 100644 config/updatekey2.asc diff --git a/.vscode/launch.json b/.vscode/launch.json index 4ee0e8e..4e702c7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,6 +10,25 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "(gdb) Attach", + "type": "cppdbg", + "request": "attach", + "program": "enter program name, for example ${workspaceFolder}/a.out", + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + }, @@ -290,9 +309,9 @@ "program": "${command:cmake.launchTargetPath}", "args": [ "--nosudo", // run without sudo (which will fail because of perms, but allow us to debug deeper into install code.) - "--prefix", "/usr", + "--disable-p2p" //"--get-current-port" - "--install" + //"--install" //"--enable-p2p" , "CA", "PiPedalTest","12345678","14" //"--list-p2p-channels" ], diff --git a/PiPedalCommon/src/include/WifiDirectConfigSettings.hpp b/PiPedalCommon/src/include/WifiDirectConfigSettings.hpp index dd15adb..fd590f3 100644 --- a/PiPedalCommon/src/include/WifiDirectConfigSettings.hpp +++ b/PiPedalCommon/src/include/WifiDirectConfigSettings.hpp @@ -37,7 +37,7 @@ namespace pipedal { std::string hotspotName_ = "pipedal"; bool pinChanged_ = false; std::string pin_; - std::string channel_ = "0"; // "0" -> select automatically. + std::string channel_ = "1"; // "0" -> select automatically. std::string wlan_ = "wlan0"; void ParseArguments(const std::vector &arguments); diff --git a/config/updatekey.gpg b/config/updatekey.asc similarity index 100% rename from config/updatekey.gpg rename to config/updatekey.asc diff --git a/config/updatekey2.asc b/config/updatekey2.asc new file mode 100644 index 0000000000000000000000000000000000000000..593c6f28f419c439779c217c3b210b86dc428fdc GIT binary patch literal 1745 zcmV;?1}^!T0gVJ^+Ss}Q3;@Z#y3z@p81Iu{0F%S7S(lx!z+`nwgF@f}H^tZ9f~n>r zE{kHn8G&!RtCfZz9{e!Px}36>vp)MUxbKJhjt91FYOLQR%z!j^+( zF2oP4ickqsnC?{E4v4bvxsK6Pj&biWWngJ7ixS}=-Z<%zeR-0TfF4A3c21Y--$z|@ zUP5`21}rX3b6#vx<Jj*QUNC4!hBS^F(yg6%`Y3Wk~lz*v-l@gxu) zdJNBf0DT~CbIibX=B+)R1XBinxnXfK|561__`=?}`h04eC+F1Tj6*Zh^YQ#8Ld@m> z9Z#mZNvEe4zbR`=++{?VnVm167nwcKVvBoJl%7o!Hk$sY@%BW;*=Yd5$7?%@slY<} z;GxoclR5N~(Vx{0B&?L5>Bii8e#xq$t| zB_F_B$=q4uFacXDj^8?u5P|TxS5xQeYt0X4ayA>R`c5xe#y|5Sy8skmVYZrC&oXpF zWYSK>Adcj!>#2^U-EDL^EQovJRFofkM`cizQz6b?4qPr@xA`+N*Xw>= zTcFx>^kIjV3ulj@N(}L0_-Vl$Hy5ksp?&_R1xn3rv41Ofkv(f{vq#@{9M;>}{uP_K zEQa`qb0XfxTR`|nt&^0246Fbsst>TOyI?D6g&IB1#ZtMxEjm6iD$6^{8PZ1=n?b`x z-pBL$%yR0M@)+^u;(wkG5jsO$hk~Rl1Q;}e%OM;xyyg%hPGTfm=cA^`0OvVZIK?sW z%U%6P+96(nFf-AqTS#~iQrCTqNMH90S9Bj*6gMV61wK@&a*M_wPHcPDaR z86>*AOuJVx#kb#{cV!vhn|v_Vx>Stt{HT{ZE&%RbHA!CP89%hMDd?tCBz zAQ8&^CQR1xfNu|6QbPguNDWIe%WI;*%F_mj5%e*6zN#p2Bnxx{{pL&Ptce8y3!pg< zI?QZ8niI1;hWVrr@muix8%p_*tLwx0RRDs0k#Af0SW*h79j*JA358x_!&VfXOD>K*9aa6DLGz2;FVcnaH zdyoCH4PAacw4QUwBR&kD8S5bupVnRZ*)4wyp8Cye``Dj=b}_WiHTvpYfRzY!F;Vvk z)ORMVEylDuyNWvM%a-cB0&s$n{Q^Q>VoUukGJ^9akyCa-lD5yE-B290xO;#S?N@@= zD%;n=&|JAb-i)C|le+KYi}t+|E)Fi%p^xBHWh?+O4GYJFXX(DPdfk(sjQBs&(Xj1W z<>aWA`g-U{*RB&sFv0$r<;LQ)?y|^?H_CB02TWrXaQl2?i3Sykx7C?`8#&Zzc^T1# za7RPP0>{sjZwOg5LU{3IW@Sf24-p%Hbxx?Qr8k3u=^HhLp`%cJdaLs0Zh7IGE nCItD-0EKq+nP(m3?0{j`mgZ~>f>R*V`Fakpmo1F+{XpFov|K~8 literal 0 HcmV?d00001 diff --git a/react/src/PiPedalModel.tsx b/react/src/PiPedalModel.tsx index f155618..7bab2ad 100644 --- a/react/src/PiPedalModel.tsx +++ b/react/src/PiPedalModel.tsx @@ -942,7 +942,7 @@ export class PiPedalModel //implements PiPedalModel return this.webSocket.connect(); }) .catch((error) => { - this.setError("Failed to connect to server."); + this.setError("Failed to connect to server." + error.toString()); return false; }) .then(() => { diff --git a/react/src/PiPedalSocket.tsx b/react/src/PiPedalSocket.tsx index 8a10bea..f611ad9 100644 --- a/react/src/PiPedalSocket.tsx +++ b/react/src/PiPedalSocket.tsx @@ -26,7 +26,7 @@ export type ReconnectHandler = () => void; export type ReconnectingHandler = (retry: number, maxRetries: number) => void; const MAX_RETRIES = 6; -const MAX_RETRY_TIME = 90*1000; +const MAX_RETRY_TIME = 90 * 1000; export type PiPedalMessageHeader = { replyTo?: number; @@ -37,10 +37,10 @@ type ReplyHandler = (header: PiPedalMessageHeader, body: any | null) => void; export interface PiPedalSocketListener { - onMessageReceived : (header: PiPedalMessageHeader, body: any | null) => void; + onMessageReceived: (header: PiPedalMessageHeader, body: any | null) => void; onError: (message: string, exception?: Error) => void; onConnectionLost: () => void; - onReconnect: () => void; + onReconnect: () => void; onReconnecting: (retry: number, maxRetries: number) => boolean; }; @@ -60,7 +60,7 @@ class PiPedalSocket { constructor( url: string, listener: PiPedalSocketListener - ) { + ) { this.url = url; this.listener = listener; } @@ -103,8 +103,7 @@ class PiPedalSocket { _replyMap: Map = new Map(); - _discardReplyReservations() - { + _discardReplyReservations() { // it's ok. All pending reservations disappear into the GC. this._replyMap = new Map(); } @@ -193,8 +192,7 @@ class PiPedalSocket { return; } - if (this.canReconnect) - { + if (this.canReconnect) { this.listener.onConnectionLost(); this._reconnect(); } @@ -212,26 +210,23 @@ class PiPedalSocket { isBackground: boolean = false; - enterBackgroundState() - { + enterBackgroundState() { this.isBackground = true; this.close(); } - exitBackgroundState() - { + exitBackgroundState() { this.isBackground = false; this._reconnect(); } reconnect() { - if (this.socket) - { + if (this.socket) { this.close(); } - if (!this.listener.onReconnecting(this.retryCount,MAX_RETRIES)) { + if (!this.listener.onReconnecting(this.retryCount, MAX_RETRIES)) { return; } ++this.retryCount; @@ -243,8 +238,7 @@ class PiPedalSocket { this.listener.onReconnect(); }) .catch(error => { - if (this.totalRetryDelay === MAX_RETRY_TIME) - { + if (this.totalRetryDelay >= MAX_RETRY_TIME) { this.listener.onError("Server connection lost."); return; } else { @@ -258,8 +252,7 @@ class PiPedalSocket { close(): void { try { - if (this.socket) - { + if (this.socket) { this.socket.onclose = null; this.socket.onerror = null; this.socket.onmessage = null; @@ -267,50 +260,54 @@ class PiPedalSocket { this.socket.close(); this.socket = undefined; } - } catch (ignored) - { + } catch (ignored) { } this.socket = undefined; } connectInternal_(): Promise { return new Promise((resolve, reject) => { - let ws = new WebSocket(this.url); + try { + let ws = new WebSocket(this.url); - let self = this; + let self = this; - ws.onmessage = this.handleMessage.bind(this); - ws.onclose = (event: Event) => { - ws.onclose = null; - ws.onerror = null; - reject("Connection closed unexpectedly."); - }; - ws.onerror = (event: Event) => { - ws.onclose = null; - ws.onerror = null; - reject("Failed to connect."); - }; - ws.onopen = (event: Event) => { - ws.onerror = self.handleError.bind(self); - ws.onclose = self.handleClose.bind(self); - ws.onopen = null; - resolve(ws); + ws.onmessage = this.handleMessage.bind(this); + ws.onclose = (event: Event) => { + ws.onclose = null; + ws.onerror = null; + reject("Connection closed unexpectedly."); + }; + ws.onerror = (event: Event) => { + ws.onclose = null; + ws.onerror = null; + reject("Failed to connect."); + }; + ws.onopen = (event: Event) => { + ws.onerror = self.handleError.bind(self); + ws.onclose = self.handleClose.bind(self); + alert("Web socket connected."); //yyy + ws.onopen = null; + resolve(ws); + }; + } catch (e: any){ + reject("Failed to connect. " + e.toString()); }; }); - } - connect(): Promise { - return new Promise((resolve, reject) => { +} +connect(): Promise < void> { + return new Promise((resolve, reject) => { - this.connectInternal_() - .then((socket) => { - this.socket = socket; - resolve(); - }) - .catch((reason) => { - reject(reason); - }); - }); - } + this.connectInternal_() + .then((socket) => { + this.socket = socket; + resolve(); + }) + .catch((reason) => { + reject(reason); + }); + }); +} } diff --git a/src/ConfigMain.cpp b/src/ConfigMain.cpp index e090b30..f17d360 100644 --- a/src/ConfigMain.cpp +++ b/src/ConfigMain.cpp @@ -771,7 +771,8 @@ void DeployVarConfig() void InstallPgpKey() { fs::path homeDir = "/var/pipedal/config/gpg"; - fs::path keyPath = "/etc/pipedal/config/updatekey.gpg"; + fs::path keyPath = "/etc/pipedal/config/updatekey.asc"; + fs::path keyPath2 = "/etc/pipedal/config/updatekey2.asc"; fs::create_directories(homeDir); std::ignore = chmod(homeDir.c_str(), 0700); @@ -781,15 +782,26 @@ void InstallPgpKey() s << (CHOWN_BIN " " SERVICE_GROUP_NAME ":" SERVICE_GROUP_NAME " ") << homeDir.c_str(); sysExec(s.str().c_str()); } - std::ostringstream ss; - ss << "/usr/bin/gpg --homedir " << homeDir.c_str() << " --import " << keyPath.c_str(); - - int rc = silentSysExec(ss.str().c_str()); - if (rc != EXIT_SUCCESS) { - cout << "Error: Failed to create update keyring." << endl; - } + std::ostringstream ss; + ss << "/usr/bin/gpg --homedir " << homeDir.c_str() << " --import " << keyPath.c_str(); + int rc = silentSysExec(ss.str().c_str()); + if (rc != EXIT_SUCCESS) + { + cout << "Error: Failed to create update keyring." << endl; + } + } + { + std::ostringstream ss; + ss << "/usr/bin/gpg --homedir " << homeDir.c_str() << " --import " << keyPath2.c_str(); + int rc = silentSysExec(ss.str().c_str()); + if (rc != EXIT_SUCCESS) + { + cout << "Error: Failed to add update key." << endl; + } + + } { std::stringstream ss; ss << (CHOWN_BIN " -R " SERVICE_GROUP_NAME ":" SERVICE_GROUP_NAME " ") << homeDir.c_str(); @@ -1396,10 +1408,11 @@ int main(int argc, char **argv) else if (disable_p2p) { WifiDirectConfigSettings settings; - settings.valid_ = true; + settings.Load(); settings.enable_ = false; SetWifiDirectConfig(settings); RestartService(true); + return EXIT_SUCCESS; } else if (enable_ap) { diff --git a/src/SetWifiConfig.cpp b/src/SetWifiConfig.cpp index 9a73245..c503c37 100644 --- a/src/SetWifiConfig.cpp +++ b/src/SetWifiConfig.cpp @@ -559,6 +559,13 @@ void UninstallP2p() } + } + if (UsingNetworkManager()) + { + // dhcpcd comes up enabled after an install, so stop it always. + sysExec(SYSTEMCTL_BIN " stop dhcpcd"); + sysExec(SYSTEMCTL_BIN " disable dhcpcd"); + } ::sync(); } diff --git a/src/Updater.cpp b/src/Updater.cpp index 2e25321..46881f4 100644 --- a/src/Updater.cpp +++ b/src/Updater.cpp @@ -847,14 +847,13 @@ void Updater::ValidateSignature(const std::filesystem::path &file, const std::fi } std::string keyId = getFingerprint(gpgText); - Lv2Log::info(unCRLF(gpgText)); // yyy delete me. - if (keyId != UPDATE_GPG_FINGERPRINT) + if (keyId != UPDATE_GPG_FINGERPRINT && keyId != UPDATE_GPG_FINGERPRINT2) { - throw std::runtime_error(SS("Update signature has the wrong fingerprint: " << keyId)); + throw std::runtime_error(SS("Update signature has the wrong id: " << keyId)); } std::string origin = getAddress(gpgText); - if (origin != UPDATE_GPG_ADDRESS) + if (origin != UPDATE_GPG_ADDRESS && origin != UPDATE_GPG_ADDRESS2) { throw std::runtime_error(SS("Update signature has an incorrect address." << origin)); } @@ -934,7 +933,6 @@ void Updater::DownloadUpdate(const std::string &url, std::filesystem::path *file responseOption = "-w \"%%{response_code}\""; // windows shell requires doubling of the %%. #endif std::string args = SS("-s -L " << responseOption << " " << url << " -o " << downloadFilePath.c_str()); - Lv2Log::info(SS("/usr/bin/curl " << args)); // yyy delete me. auto curlOutput = sysExecForOutput("/usr/bin/curl", args); if (curlOutput.exitCode != EXIT_SUCCESS || badOutput(downloadFilePath)) { @@ -944,7 +942,6 @@ void Updater::DownloadUpdate(const std::string &url, std::filesystem::path *file checkCurlHttpResponse(curlOutput.output); args = SS("-s -L " << responseOption << " " << signatureUrl << " -o " << downloadSignaturePath.c_str()); - Lv2Log::info(SS("/usr/bin/curl " << args)); curlOutput = sysExecForOutput("/usr/bin/curl", args); if (curlOutput.exitCode != EXIT_SUCCESS || badOutput(downloadSignaturePath)) diff --git a/src/UpdaterSecurity.hpp b/src/UpdaterSecurity.hpp index 774ee10..a27bd0b 100644 --- a/src/UpdaterSecurity.hpp +++ b/src/UpdaterSecurity.hpp @@ -42,10 +42,17 @@ #ifndef UPDATE_GPG_ADDRESS #define UPDATE_GPG_ADDRESS "Robin Davies " #endif +#ifndef UPDATE_GPG_ADDRESS2 +#define UPDATE_GPG_ADDRESS2 "PiPedal Project " +#endif + #ifndef UPDATE_GPG_FINGERPRINT #define UPDATE_GPG_FINGERPRINT "381124E2BB4478D225D2313B2AEF3F7BD53EAA59" #endif +#ifndef UPDATE_GPG_FINGERPRINT2 +#define UPDATE_GPG_FINGERPRINT2 "2D1F39DBB1F819412B678F88E9D7081E08E3D85C" +#endif // Configuration for downloading of updates. diff --git a/src/WebServerConfig.cpp b/src/WebServerConfig.cpp index f88a4e1..fbba021 100644 --- a/src/WebServerConfig.cpp +++ b/src/WebServerConfig.cpp @@ -401,7 +401,6 @@ public: if (patchProperty.length() == 0 && directory.length() == 0) { - // yyy no throwing! throw PiPedalException("Malformed request."); }