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 0000000..593c6f2 Binary files /dev/null and b/config/updatekey2.asc differ 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."); }