diff --git a/include/image.mk b/include/image.mk index 3d5d6c1613..62e05b2567 100644 --- a/include/image.mk +++ b/include/image.mk @@ -277,11 +277,13 @@ endef define Image/Manifest $(call opkg,$(TARGET_DIR_ORIG)) list-installed > \ $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest +ifndef IB $(if $(CONFIG_JSON_CYCLONEDX_SBOM), \ $(SCRIPT_DIR)/package-metadata.pl imgcyclonedxsbom \ $(TMP_DIR)/.packageinfo \ $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest > \ $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).bom.cdx.json) +endif endef define Image/gzip-ext4-padded-squashfs diff --git a/package/boot/uboot-mediatek/patches/450-add-cmcc_rax3000m.patch b/package/boot/uboot-mediatek/patches/437-add-cmcc_rax3000m.patch similarity index 100% rename from package/boot/uboot-mediatek/patches/450-add-cmcc_rax3000m.patch rename to package/boot/uboot-mediatek/patches/437-add-cmcc_rax3000m.patch diff --git a/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh b/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh index 098feffe20..0df915a70d 100644 --- a/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh +++ b/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh @@ -940,7 +940,7 @@ mac80211_setup_supplicant() { if [ "$mode" = "sta" ]; then wpa_supplicant_add_network "$ifname" else - wpa_supplicant_add_network "$ifname" "$freq" "$htmode" "$noscan" + wpa_supplicant_add_network "$ifname" "$freq" "$htmode" "$hostapd_noscan" fi wpa_supplicant_add_interface "$ifname" "$mode" diff --git a/package/libs/mbedtls/Config.in b/package/libs/mbedtls/Config.in index 92d7180f56..d496607a98 100644 --- a/package/libs/mbedtls/Config.in +++ b/package/libs/mbedtls/Config.in @@ -104,7 +104,7 @@ config MBEDTLS_ECP_DP_SECP384R1_ENABLED config MBEDTLS_ECP_DP_SECP521R1_ENABLED bool "MBEDTLS_ECP_DP_SECP521R1_ENABLED" - default n + default y config MBEDTLS_ECP_DP_SECP192K1_ENABLED bool "MBEDTLS_ECP_DP_SECP192K1_ENABLED" diff --git a/package/libs/mbedtls/Makefile b/package/libs/mbedtls/Makefile index 5048a3cc5f..45005ad5a1 100644 --- a/package/libs/mbedtls/Makefile +++ b/package/libs/mbedtls/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mbedtls PKG_VERSION:=2.28.5 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_BUILD_FLAGS:=no-mips16 gc-sections no-lto PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz diff --git a/package/network/config/netifd/Makefile b/package/network/config/netifd/Makefile index 44d3a98d8f..8d9795c068 100644 --- a/package/network/config/netifd/Makefile +++ b/package/network/config/netifd/Makefile @@ -5,9 +5,9 @@ PKG_RELEASE:=1 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL=$(PROJECT_GIT)/project/netifd.git -PKG_SOURCE_DATE:=2023-10-20 -PKG_SOURCE_VERSION:=5590a80e2566d378be955f61c287a63fb3bdf329 -PKG_MIRROR_HASH:=eef792b4e9fa7a5227cf8c2ec4ed5e6558dd04c119cd9f97561923821fd1aa92 +PKG_SOURCE_DATE:=2023-11-07 +PKG_SOURCE_VERSION:=516ab774cc16d4b04b3b17a067cbf2649f1adaeb +PKG_MIRROR_HASH:=76dcc7988d8ade7e8a80af8a79e9b509093c5eea9e785b0e5f7aef845787118a PKG_MAINTAINER:=Felix Fietkau PKG_LICENSE:=GPL-2.0 diff --git a/package/network/services/hostapd/Makefile b/package/network/services/hostapd/Makefile index 73ec5e198d..f46c6275ef 100644 --- a/package/network/services/hostapd/Makefile +++ b/package/network/services/hostapd/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=hostapd -PKG_RELEASE:=5 +PKG_RELEASE:=6 PKG_SOURCE_URL:=http://w1.fi/hostap.git PKG_SOURCE_PROTO:=git diff --git a/package/network/services/hostapd/files/common.uc b/package/network/services/hostapd/files/common.uc index ccffe3eb43..4c33779af9 100644 --- a/package/network/services/hostapd/files/common.uc +++ b/package/network/services/hostapd/files/common.uc @@ -10,6 +10,36 @@ const iftypes = { monitor: nl80211.const.NL80211_IFTYPE_MONITOR, }; +const mesh_params = { + mesh_retry_timeout: "retry_timeout", + mesh_confirm_timeout: "confirm_timeout", + mesh_holding_timeout: "holding_timeout", + mesh_max_peer_links: "max_peer_links", + mesh_max_retries: "max_retries", + mesh_ttl: "ttl", + mesh_element_ttl: "element_ttl", + mesh_auto_open_plinks: "auto_open_plinks", + mesh_hwmp_max_preq_retries: "hwmp_max_preq_retries", + mesh_path_refresh_time: "path_refresh_time", + mesh_min_discovery_timeout: "min_discovery_timeout", + mesh_hwmp_active_path_timeout: "hwmp_active_path_timeout", + mesh_hwmp_preq_min_interval: "hwmp_preq_min_interval", + mesh_hwmp_net_diameter_traversal_time: "hwmp_net_diam_trvs_time", + mesh_hwmp_rootmode: "hwmp_rootmode", + mesh_hwmp_rann_interval: "hwmp_rann_interval", + mesh_gate_announcements: "gate_announcements", + mesh_sync_offset_max_neighor: "sync_offset_max_neighbor", + mesh_rssi_threshold: "rssi_threshold", + mesh_hwmp_active_path_to_root_timeout: "hwmp_path_to_root_timeout", + mesh_hwmp_root_interval: "hwmp_root_interval", + mesh_hwmp_confirmation_interval: "hwmp_confirmation_interval", + mesh_awake_window: "awake_window", + mesh_plink_timeout: "plink_timeout", + mesh_fwding: "forwarding", + mesh_power_mode: "power_mode", + mesh_nolearn: "nolearn" +}; + function wdev_remove(name) { nl80211.request(nl80211.const.NL80211_CMD_DEL_INTERFACE, 0, { dev: name }); @@ -94,6 +124,31 @@ function wdev_create(phy, name, data) return null; } +function wdev_set_mesh_params(name, data) +{ + let mesh_cfg = {}; + + for (let key in mesh_params) { + let val = data[key]; + if (val == null) + continue; + mesh_cfg[mesh_params[key]] = int(val); + } + + if (!length(mesh_cfg)) + return null; + + nl80211.request(nl80211.const.NL80211_CMD_SET_MESH_CONFIG, 0, + { dev: name, mesh_params: mesh_cfg }); + + return nl80211.error(); +} + +function wdev_set_up(name, up) +{ + rtnl.request(rtnl.const.RTM_SETLINK, 0, { dev: name, change: 1, flags: up ? 1 : 0 }); +} + function phy_sysfs_file(phy, name) { return trim(readfile(`/sys/class/ieee80211/${phy}/${name}`)); @@ -315,4 +370,4 @@ function vlist_new(cb) { }, vlist_proto); } -export { wdev_remove, wdev_create, is_equal, vlist_new, phy_is_fullmac, phy_open }; +export { wdev_remove, wdev_create, wdev_set_mesh_params, wdev_set_up, is_equal, vlist_new, phy_is_fullmac, phy_open }; diff --git a/package/network/services/hostapd/files/wdev.uc b/package/network/services/hostapd/files/wdev.uc index cf438f7715..ff4d629fd6 100644 --- a/package/network/services/hostapd/files/wdev.uc +++ b/package/network/services/hostapd/files/wdev.uc @@ -1,6 +1,6 @@ #!/usr/bin/env ucode 'use strict'; -import { vlist_new, is_equal, wdev_create, wdev_remove, phy_open } from "/usr/share/hostap/common.uc"; +import { vlist_new, is_equal, wdev_create, wdev_set_mesh_params, wdev_remove, wdev_set_up, phy_open } from "/usr/share/hostap/common.uc"; import { readfile, writefile, basename, readlink, glob } from "fs"; let libubus = require("ubus"); @@ -9,17 +9,6 @@ let phy = shift(ARGV); let command = shift(ARGV); let phydev; -const mesh_params = [ - "mesh_retry_timeout", "mesh_confirm_timeout", "mesh_holding_timeout", "mesh_max_peer_links", - "mesh_max_retries", "mesh_ttl", "mesh_element_ttl", "mesh_hwmp_max_preq_retries", - "mesh_path_refresh_time", "mesh_min_discovery_timeout", "mesh_hwmp_active_path_timeout", - "mesh_hwmp_preq_min_interval", "mesh_hwmp_net_diameter_traversal_time", "mesh_hwmp_rootmode", - "mesh_hwmp_rann_interval", "mesh_gate_announcements", "mesh_sync_offset_max_neighor", - "mesh_rssi_threshold", "mesh_hwmp_active_path_to_root_timeout", "mesh_hwmp_root_interval", - "mesh_hwmp_confirmation_interval", "mesh_awake_window", "mesh_plink_timeout", - "mesh_auto_open_plinks", "mesh_fwding", "mesh_power_mode" -]; - function iface_stop(wdev) { if (keep_devices[wdev.ifname]) @@ -33,7 +22,7 @@ function iface_start(wdev) let ifname = wdev.ifname; if (readfile(`/sys/class/net/${ifname}/ifindex`)) { - system([ "ip", "link", "set", "dev", ifname, "down" ]); + wdev_set_up(ifname, false); wdev_remove(ifname); } let wdev_config = {}; @@ -42,7 +31,7 @@ function iface_start(wdev) if (!wdev_config.macaddr && wdev.mode != "monitor") wdev_config.macaddr = phydev.macaddr_next(); wdev_create(phy, ifname, wdev_config); - system([ "ip", "link", "set", "dev", ifname, "up" ]); + wdev_set_up(ifname, true); if (wdev.freq) system(`iw dev ${ifname} set freq ${wdev.freq} ${wdev.htmode}`); if (wdev.mode == "adhoc") { @@ -60,19 +49,8 @@ function iface_start(wdev) push(cmd, key, wdev[key]); system(cmd); - cmd = ["iw", "dev", ifname, "set", "mesh_param" ]; - let len = length(cmd); - - for (let param in mesh_params) - if (wdev[param]) - push(cmd, param, wdev[param]); - - if (len == length(cmd)) - return; - - system(cmd); + wdev_set_mesh_params(ifname, wdev); } - } function iface_cb(new_if, old_if) diff --git a/package/network/services/hostapd/files/wpa_supplicant.uc b/package/network/services/hostapd/files/wpa_supplicant.uc index cb5f41b1af..d624f27cdd 100644 --- a/package/network/services/hostapd/files/wpa_supplicant.uc +++ b/package/network/services/hostapd/files/wpa_supplicant.uc @@ -1,6 +1,6 @@ let libubus = require("ubus"); import { open, readfile } from "fs"; -import { wdev_create, wdev_remove, is_equal, vlist_new, phy_open } from "common"; +import { wdev_create, wdev_set_mesh_params, wdev_remove, is_equal, wdev_set_up, vlist_new, phy_open } from "common"; let ubus = libubus.connect(); @@ -40,6 +40,7 @@ function iface_start(phydev, iface, macaddr_list) let ret = wdev_create(phy, ifname, wdev_config); if (ret) wpas.printf(`Failed to create device ${ifname}: ${ret}`); + wdev_set_up(ifname, true); wpas.add_iface(iface.config); iface.running = true; } @@ -316,6 +317,23 @@ return { } iface_hostapd_notify(phy, ifname, iface, state); + + if (state != "COMPLETED") + return; + + let phy_data = wpas.data.config[phy]; + if (!phy_data) + return; + + let iface_data = phy_data.data[ifname]; + if (!iface_data) + return; + + let wdev_config = iface_data.config; + if (!wdev_config || wdev_config.mode != "mesh") + return; + + wdev_set_mesh_params(ifname, wdev_config); }, event: function(ifname, iface, ev, info) { let phy = wpas.data.iface_phy[ifname]; diff --git a/package/network/services/hostapd/patches/301-mesh-noscan.patch b/package/network/services/hostapd/patches/301-mesh-noscan.patch index 6b5416f0ea..ceb6d0c161 100644 --- a/package/network/services/hostapd/patches/301-mesh-noscan.patch +++ b/package/network/services/hostapd/patches/301-mesh-noscan.patch @@ -24,8 +24,8 @@ frequency); goto out_free; } -+ if (ssid->noscan) -+ conf->noscan = 1; ++ if (conf->noscan) ++ ssid->noscan = 1; if (ssid->mesh_basic_rates == NULL) { /* @@ -45,7 +45,7 @@ unsigned int j; static const int ht40plus[] = { - 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157, 165, 173, -+ 1, 2, 3, 4, 5, 6, 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157, 165, 173, ++ 1, 2, 3, 4, 5, 6, 7, 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157, 165, 173, 184, 192 }; int ht40 = -1; @@ -58,6 +58,15 @@ u8 channel; bool is_6ghz; bool dfs_enabled = wpa_s->conf->country[0] && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_RADAR); +@@ -3080,6 +3080,8 @@ void ibss_mesh_setup_freq(struct wpa_sup + freq->he_enabled = ibss_mesh_can_use_he(wpa_s, ssid, mode, + ieee80211_mode); + freq->channel = channel; ++ if (mode->mode == HOSTAPD_MODE_IEEE80211G && ssid->noscan) ++ ibss_mesh_select_40mhz(wpa_s, ssid, mode, freq, obss_scan, dfs_enabled); + /* Setup higher BW only for 5 GHz */ + if (mode->mode == HOSTAPD_MODE_IEEE80211A) { + ibss_mesh_select_40mhz(wpa_s, ssid, mode, freq, obss_scan, dfs_enabled); --- a/wpa_supplicant/config_ssid.h +++ b/wpa_supplicant/config_ssid.h @@ -1035,6 +1035,8 @@ struct wpa_ssid { diff --git a/package/network/services/hostapd/patches/310-rescan_immediately.patch b/package/network/services/hostapd/patches/310-rescan_immediately.patch index e12b2059b3..6e0244bca2 100644 --- a/package/network/services/hostapd/patches/310-rescan_immediately.patch +++ b/package/network/services/hostapd/patches/310-rescan_immediately.patch @@ -1,6 +1,6 @@ --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c -@@ -5767,7 +5767,7 @@ wpa_supplicant_alloc(struct wpa_supplica +@@ -5769,7 +5769,7 @@ wpa_supplicant_alloc(struct wpa_supplica if (wpa_s == NULL) return NULL; wpa_s->scan_req = INITIAL_SCAN_REQ; diff --git a/package/network/services/hostapd/patches/460-wpa_supplicant-add-new-config-params-to-be-used-with.patch b/package/network/services/hostapd/patches/460-wpa_supplicant-add-new-config-params-to-be-used-with.patch index c6fe54efed..dc19553e26 100644 --- a/package/network/services/hostapd/patches/460-wpa_supplicant-add-new-config-params-to-be-used-with.patch +++ b/package/network/services/hostapd/patches/460-wpa_supplicant-add-new-config-params-to-be-used-with.patch @@ -174,7 +174,7 @@ Signed-hostap: Antonio Quartulli * macsec_policy - Determines the policy for MACsec secure session --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c -@@ -4175,6 +4175,12 @@ static void wpas_start_assoc_cb(struct w +@@ -4177,6 +4177,12 @@ static void wpas_start_assoc_cb(struct w params.beacon_int = ssid->beacon_int; else params.beacon_int = wpa_s->conf->beacon_int; diff --git a/package/network/services/hostapd/patches/600-ubus_support.patch b/package/network/services/hostapd/patches/600-ubus_support.patch index bc80ef0e81..a6ccf83331 100644 --- a/package/network/services/hostapd/patches/600-ubus_support.patch +++ b/package/network/services/hostapd/patches/600-ubus_support.patch @@ -348,7 +348,7 @@ CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c -@@ -7593,6 +7593,8 @@ struct wpa_supplicant * wpa_supplicant_a +@@ -7595,6 +7595,8 @@ struct wpa_supplicant * wpa_supplicant_a } #endif /* CONFIG_P2P */ @@ -357,7 +357,7 @@ return wpa_s; } -@@ -7619,6 +7621,8 @@ int wpa_supplicant_remove_iface(struct w +@@ -7621,6 +7623,8 @@ int wpa_supplicant_remove_iface(struct w struct wpa_supplicant *parent = wpa_s->parent; #endif /* CONFIG_MESH */ @@ -366,7 +366,7 @@ /* Remove interface from the global list of interfaces */ prev = global->ifaces; if (prev == wpa_s) { -@@ -7965,8 +7969,12 @@ int wpa_supplicant_run(struct wpa_global +@@ -7967,8 +7971,12 @@ int wpa_supplicant_run(struct wpa_global eloop_register_signal_terminate(wpa_supplicant_terminate, global); eloop_register_signal_reconfig(wpa_supplicant_reconfig, global); diff --git a/package/network/services/hostapd/patches/601-ucode_support.patch b/package/network/services/hostapd/patches/601-ucode_support.patch index de182b985d..23f535b685 100644 --- a/package/network/services/hostapd/patches/601-ucode_support.patch +++ b/package/network/services/hostapd/patches/601-ucode_support.patch @@ -196,7 +196,7 @@ #ifdef CONFIG_BGSCAN if (state == WPA_COMPLETED && wpa_s->current_ssid != wpa_s->bgscan_ssid) -@@ -7594,6 +7595,7 @@ struct wpa_supplicant * wpa_supplicant_a +@@ -7596,6 +7597,7 @@ struct wpa_supplicant * wpa_supplicant_a #endif /* CONFIG_P2P */ wpas_ubus_add_bss(wpa_s); @@ -204,7 +204,7 @@ return wpa_s; } -@@ -7621,6 +7623,7 @@ int wpa_supplicant_remove_iface(struct w +@@ -7623,6 +7625,7 @@ int wpa_supplicant_remove_iface(struct w struct wpa_supplicant *parent = wpa_s->parent; #endif /* CONFIG_MESH */ @@ -212,7 +212,7 @@ wpas_ubus_free_bss(wpa_s); /* Remove interface from the global list of interfaces */ -@@ -7931,6 +7934,7 @@ struct wpa_global * wpa_supplicant_init( +@@ -7933,6 +7936,7 @@ struct wpa_global * wpa_supplicant_init( eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0, wpas_periodic, global, NULL); @@ -220,7 +220,7 @@ return global; } -@@ -7969,12 +7973,8 @@ int wpa_supplicant_run(struct wpa_global +@@ -7971,12 +7975,8 @@ int wpa_supplicant_run(struct wpa_global eloop_register_signal_terminate(wpa_supplicant_terminate, global); eloop_register_signal_reconfig(wpa_supplicant_reconfig, global); @@ -233,7 +233,7 @@ return 0; } -@@ -8007,6 +8007,8 @@ void wpa_supplicant_deinit(struct wpa_gl +@@ -8009,6 +8009,8 @@ void wpa_supplicant_deinit(struct wpa_gl wpas_notify_supplicant_deinitialized(global); diff --git a/package/utils/px5g-mbedtls/Makefile b/package/utils/px5g-mbedtls/Makefile index 6de5e55d06..14c9f684a9 100644 --- a/package/utils/px5g-mbedtls/Makefile +++ b/package/utils/px5g-mbedtls/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=px5g-mbedtls -PKG_RELEASE:=9 +PKG_RELEASE:=10 PKG_LICENSE:=LGPL-2.1 PKG_BUILD_FLAGS:=no-mips16 diff --git a/package/utils/px5g-mbedtls/px5g-mbedtls.c b/package/utils/px5g-mbedtls/px5g-mbedtls.c index 4e0a73ab0a..85abe7dc73 100644 --- a/package/utils/px5g-mbedtls/px5g-mbedtls.c +++ b/package/utils/px5g-mbedtls/px5g-mbedtls.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -55,10 +56,13 @@ static int _urandom(void *ctx, unsigned char *out, size_t len) return 0; } -static void write_file(const char *path, int len, bool pem) +static void write_file(const char *path, size_t len, bool pem, bool cert) { - FILE *f = stdout; + mode_t mode = S_IRUSR | S_IWUSR; const char *buf_start = buf; + int fd = STDERR_FILENO; + ssize_t written; + int err; if (!pem) buf_start += sizeof(buf) - len; @@ -67,17 +71,30 @@ static void write_file(const char *path, int len, bool pem) fprintf(stderr, "No data to write\n"); exit(1); } + + if (cert) + mode |= S_IRGRP | S_IROTH; - if (!f) { + if (path) + fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, mode); + + if (fd < 0) { fprintf(stderr, "error: I/O error\n"); exit(1); } + written = write(fd, buf_start, len); + if (written != len) { + fprintf(stderr, "writing key failed with: %s\n", strerror(errno)); + exit(1); + } + err = fsync(fd); + if (err < 0) { + fprintf(stderr, "syncing key failed with: %s\n", strerror(errno)); + exit(1); + } if (path) - f = fopen(path, "w"); - - fwrite(buf_start, 1, len, f); - fclose(f); + close(fd); } static mbedtls_ecp_group_id ecp_curve(const char *name) @@ -110,7 +127,7 @@ static void write_key(mbedtls_pk_context *key, const char *path, bool pem) len = 0; } - write_file(path, len, pem); + write_file(path, len, pem, false); } static void gen_key(mbedtls_pk_context *key, bool rsa, int ksize, int exp, @@ -301,7 +318,7 @@ int selfsigned(char **arg) return 1; } } - write_file(certpath, len, pem); + write_file(certpath, len, pem, true); mbedtls_x509write_crt_free(&cert); mbedtls_mpi_free(&serial); diff --git a/package/utils/px5g-wolfssl/Makefile b/package/utils/px5g-wolfssl/Makefile index 843f03fcc1..ba208f6ca5 100644 --- a/package/utils/px5g-wolfssl/Makefile +++ b/package/utils/px5g-wolfssl/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=px5g-wolfssl -PKG_RELEASE:=8.2 +PKG_RELEASE:=9 PKG_LICENSE:=GPL-2.0-or-later PKG_BUILD_FLAGS:=no-mips16 diff --git a/package/utils/px5g-wolfssl/px5g-wolfssl.c b/package/utils/px5g-wolfssl/px5g-wolfssl.c index cd04a41dfb..755d370ba2 100644 --- a/package/utils/px5g-wolfssl/px5g-wolfssl.c +++ b/package/utils/px5g-wolfssl/px5g-wolfssl.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -24,27 +26,38 @@ enum { RSA_KEY_TYPE = 1, }; -int write_file(byte *buf, int bufSz, char *path) { - int ret; - FILE *file; +int write_file(byte *buf, int bufSz, char *path, bool cert) { + mode_t mode = S_IRUSR | S_IWUSR; + ssize_t written; + int err; + int fd; + + if (cert) + mode |= S_IRGRP | S_IROTH; + if (path) { - file = fopen(path, "wb"); - if (file == NULL) { + fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, mode); + if (fd < 0) { perror("Error opening file"); exit(1); } } else { - file = stdout; + fd = STDERR_FILENO; + } + written = write(fd, buf, bufSz); + if (written != bufSz) { + perror("Error write file"); + exit(1); + } + err = fsync(fd); + if (err < 0) { + perror("Error fsync file"); + exit(1); } - ret = (int)fwrite(buf, 1, bufSz, file); if (path) { - fclose(file); + close(fd); } - if (ret > 0) { - /* ret > 0 indicates a successful file write, set to zero for return */ - ret = 0; - } - return ret; + return 0; } int write_key(ecc_key *ecKey, RsaKey *rsaKey, int type, int keySz, char *fName, @@ -73,9 +86,9 @@ int write_key(ecc_key *ecKey, RsaKey *rsaKey, int type, int keySz, char *fName, fprintf(stderr, "DER to PEM failed: %d\n", ret); } pemSz = ret; - ret = write_file(pem, pemSz, fName); + ret = write_file(pem, pemSz, fName, false); } else { - ret = write_file(der, derSz, fName); + ret = write_file(der, derSz, fName, false); } return ret; } @@ -281,7 +294,7 @@ int selfsigned(WC_RNG *rng, char **arg) { } pemSz = ret; - ret = write_file(pemBuf, pemSz, certpath); + ret = write_file(pemBuf, pemSz, certpath, true); if (ret != 0) { fprintf(stderr, "Write Cert failed: %d\n", ret); return ret; diff --git a/package/utils/ucode/Makefile b/package/utils/ucode/Makefile index b62633492a..067e56e02d 100644 --- a/package/utils/ucode/Makefile +++ b/package/utils/ucode/Makefile @@ -12,9 +12,9 @@ PKG_RELEASE:=1 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL=https://github.com/jow-/ucode.git -PKG_SOURCE_DATE:=2023-11-02 -PKG_SOURCE_VERSION:=cfb24ea4f12131dcefe4f1ede2f51d3d16b88dec -PKG_MIRROR_HASH:=f515a23ab438f92be5788c42b9f614a82e670de2df1c01cd63143cdc77fa24fe +PKG_SOURCE_DATE:=2023-11-07 +PKG_SOURCE_VERSION:=a6e75e02528e36f3610a7f0073453018336def2e +PKG_MIRROR_HASH:=e1a0f98ba865ed5911d5db3bfca55a2f1b825992bf5f7c7e324928d9412d7ae2 PKG_MAINTAINER:=Jo-Philipp Wich PKG_LICENSE:=ISC