From 9176b9c77c8ecae0087d2c3189b90db3a819a668 Mon Sep 17 00:00:00 2001 From: viktorxda <35473052+viktorxda@users.noreply.github.com> Date: Tue, 28 Jan 2025 15:24:50 +0100 Subject: [PATCH] [no ci] wifibroadcast-ng: add custom keypair generator --- Makefile | 2 +- .../sigmastar-osdrv-infinity6.mk | 3 +- .../wifibroadcast-ng/files/wifibroadcast | 9 ++- .../package/wifibroadcast-ng/src/keypair.c | 60 +++++++++++++++++++ .../wifibroadcast-ng/wifibroadcast-ng.mk | 2 + 5 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 general/package/wifibroadcast-ng/src/keypair.c diff --git a/Makefile b/Makefile index 17b06443..382c4a2e 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ build: defconfig @$(BR_MAKE) all -j$(shell nproc) br-%: defconfig - @$(BR_MAKE) $(subst br-,,$@) + @$(BR_MAKE) $(subst br-,,$@) -j$(shell nproc) defconfig: prepare @echo --- $(or $(CONFIG),$(error variable BOARD not found)) diff --git a/general/package/sigmastar-osdrv-infinity6/sigmastar-osdrv-infinity6.mk b/general/package/sigmastar-osdrv-infinity6/sigmastar-osdrv-infinity6.mk index 50f4146b..b9443364 100644 --- a/general/package/sigmastar-osdrv-infinity6/sigmastar-osdrv-infinity6.mk +++ b/general/package/sigmastar-osdrv-infinity6/sigmastar-osdrv-infinity6.mk @@ -12,8 +12,7 @@ SIGMASTAR_OSDRV_INFINITY6_LICENSE_FILES = LICENSE SIGMASTAR_OSDRV_INFINITY6_DEPENDENCIES = ipctool sigmastar-osdrv-sensors define SIGMASTAR_OSDRV_INFINITY6_BUILD_CMDS - cp -rf $(SIGMASTAR_OSDRV_INFINITY6_PKGDIR)/files/src $(@D) - $(TARGET_CC) $(@D)/src/config_tool.c -o $(@D)/config_tool -lipchw -s + $(TARGET_CC) $(SIGMASTAR_OSDRV_INFINITY6_PKGDIR)/src/config_tool.c -o $(@D)/config_tool -lipchw -s endef define SIGMASTAR_OSDRV_INFINITY6_INSTALL_TARGET_CMDS diff --git a/general/package/wifibroadcast-ng/files/wifibroadcast b/general/package/wifibroadcast-ng/files/wifibroadcast index 350acaf7..e685dc48 100755 --- a/general/package/wifibroadcast-ng/files/wifibroadcast +++ b/general/package/wifibroadcast-ng/files/wifibroadcast @@ -14,6 +14,10 @@ wfb_yaml() { load_config() { wfb_yaml /rom/etc/wfb.yaml wfb_yaml /etc/wfb.yaml + + if [ ! -e "$wfb_key" ]; then + wfb_key=/rom/etc/drone.key + fi } load_modules() { @@ -91,8 +95,9 @@ start_telemetry() { if [ "$router" = "msposd" ]; then echo "- Starting $router" - msposd --baudrate 115200 --channels 8 -osd --ahi 0 -r "$osd_fps" \ - --master "$serial" --out 10.5.0.1:14551 > /dev/null & + size=$(curl -s localhost/api/v1/config.json | jsonfilter -e "@.video0.size") + msposd --baudrate 115200 --channels 8 --ahi 0 -osd -r "$osd_fps" \ + --master "$serial" --out 10.5.0.1:14551 --size "${size:-1280x720}" > /dev/null & elif [ "$router" = "mavfwd" ]; then echo "- Starting $router" mavfwd --baudrate 115200 --channels 8 -p 100 -a 15 -t \ diff --git a/general/package/wifibroadcast-ng/src/keypair.c b/general/package/wifibroadcast-ng/src/keypair.c new file mode 100644 index 00000000..a4167bce --- /dev/null +++ b/general/package/wifibroadcast-ng/src/keypair.c @@ -0,0 +1,60 @@ +// Copyright (C) 2017 - 2024 Vasily Evseenko + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include + +int main(int argc, char **argv) { + unsigned char drone_publickey[crypto_box_PUBLICKEYBYTES]; + unsigned char drone_secretkey[crypto_box_SECRETKEYBYTES]; + unsigned char gs_publickey[crypto_box_PUBLICKEYBYTES]; + unsigned char gs_secretkey[crypto_box_SECRETKEYBYTES]; + FILE *fp; + + if (argc != 2) { + printf("Passphrase is missing\n"); + return 1; + } + + if (sodium_init() < 0) { + printf("Libsodium init failed\n"); + return 1; + } + + const char *seed = argv[1]; + printf("Using passphrase: %s\n", seed); + + if (crypto_box_seed_keypair(drone_publickey, drone_secretkey, seed) != 0 || + crypto_box_seed_keypair(gs_publickey, gs_secretkey, seed) != 0) { + printf("Unable to generate keys\n"); + return 1; + } + + const char *key = "/etc/drone.key"; + if ((fp = fopen(key, "w")) == NULL) { + printf("Unable to save: %s\n", key); + return 1; + } + + fwrite(drone_secretkey, crypto_box_SECRETKEYBYTES, 1, fp); + fwrite(gs_publickey, crypto_box_PUBLICKEYBYTES, 1, fp); + fclose(fp); + + printf("Drone keypair saved: %s\n", key); + + return 0; +} diff --git a/general/package/wifibroadcast-ng/wifibroadcast-ng.mk b/general/package/wifibroadcast-ng/wifibroadcast-ng.mk index 3cedfe51..ae40fc22 100644 --- a/general/package/wifibroadcast-ng/wifibroadcast-ng.mk +++ b/general/package/wifibroadcast-ng/wifibroadcast-ng.mk @@ -12,6 +12,7 @@ WIFIBROADCAST_NG_DEPENDENCIES += libpcap libsodium define WIFIBROADCAST_NG_BUILD_CMDS $(MAKE) CC=$(TARGET_CC) CXX=$(TARGET_CXX) LDFLAGS=-s -C $(@D) all_bin + $(TARGET_CC) $(WIFIBROADCAST_NG_PKGDIR)/src/keypair.c -o $(@D)/keypair -lsodium -s endef define WIFIBROADCAST_NG_INSTALL_TARGET_CMDS @@ -23,6 +24,7 @@ define WIFIBROADCAST_NG_INSTALL_TARGET_CMDS $(INSTALL) -m 755 -t $(TARGET_DIR)/etc/init.d $(WIFIBROADCAST_NG_PKGDIR)/files/S98wifibroadcast $(INSTALL) -m 755 -d $(TARGET_DIR)/usr/bin + $(INSTALL) -m 755 -t $(TARGET_DIR)/usr/bin $(@D)/keypair $(INSTALL) -m 755 -t $(TARGET_DIR)/usr/bin $(@D)/wfb_rx $(INSTALL) -m 755 -t $(TARGET_DIR)/usr/bin $(@D)/wfb_tx $(INSTALL) -m 755 -t $(TARGET_DIR)/usr/bin $(@D)/wfb_tx_cmd