From 37b29f689951db02cbace46e4896b91f2efec6ad Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 16 Nov 2024 19:36:55 -0600 Subject: [PATCH 1/6] Add littlefswebui --- .github/workflows/main_matrix.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index efdbd2637..37164b758 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -203,6 +203,7 @@ jobs: ./device-*.sh ./device-*.bat ./littlefs-*.bin + ./littlefswebui-*.bin ./bleota*bin ./Meshtastic_nRF52_factory_erase*.uf2 retention-days: 30 From 19e563f9ca95259c9d3731c7720eee64bff85fab Mon Sep 17 00:00:00 2001 From: gjelsoe <36234524+gjelsoe@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:38:19 +0100 Subject: [PATCH 2/6] more userPrefs.h Added PKI Admin keys to userPrefs.h --- src/mesh/NodeDB.cpp | 27 ++++++++++++++++++++++++--- userPrefs.h | 16 +++++++++------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 7f051ae16..d0b106f22 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -407,9 +407,30 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) config.lora.ignore_mqtt = false; #endif #ifdef USERPREFS_USE_ADMIN_KEY - memcpy(config.security.admin_key[0].bytes, USERPREFS_ADMIN_KEY, 32); - config.security.admin_key[0].size = 32; - config.security.admin_key_count = 1; + // Initialize admin_key_count to zero + byte numAdminKeys = 0; + +// Check if USERPREFS_ADMIN_KEY_0 is non-empty +if (sizeof(USERPREFS_ADMIN_KEY_0) > 0) { + memcpy(config.security.admin_key[numAdminKeys].bytes, USERPREFS_ADMIN_KEY_0, 32); + config.security.admin_key[numAdminKeys].size = 32; + numAdminKeys++; +} + +// Check if USERPREFS_ADMIN_KEY_1 is non-empty +if (sizeof(USERPREFS_ADMIN_KEY_1) > 0) { + memcpy(config.security.admin_key[numAdminKeys].bytes, USERPREFS_ADMIN_KEY_1, 32); + config.security.admin_key[numAdminKeys].size = 32; + numAdminKeys++; +} + +// Check if USERPREFS_ADMIN_KEY_2 is non-empty +if (sizeof(USERPREFS_ADMIN_KEY_2) > 0) { + memcpy(config.security.admin_key[config.security.admin_key_count].bytes, USERPREFS_ADMIN_KEY_2, 32); + config.security.admin_key[config.security.admin_key_count].size = 32; + numAdminKeys++; +} + config.security.admin_key_count = numAdminKeys; #endif if (shouldPreserveKey) { config.security.private_key.size = 32; diff --git a/userPrefs.h b/userPrefs.h index c105e6b52..24331d413 100644 --- a/userPrefs.h +++ b/userPrefs.h @@ -28,13 +28,13 @@ // #define USERPREFS_CHANNEL_0_PRECISION 14 // #define USERPREFS_CHANNEL_0_UPLINK_ENABLED true // #define USERPREFS_CHANNEL_0_DOWNLINK_ENABLED true -/* + #define USERPREFS_CHANNEL_1_PSK \ { \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \ } -*/ + // #define USERPREFS_CHANNEL_1_NAME "REPLACEME" // #define USERPREFS_CHANNEL_1_PRECISION 14 // #define USERPREFS_CHANNEL_1_UPLINK_ENABLED true @@ -68,12 +68,14 @@ static unsigned char icon_bits[] = { 0x98, 0x3F, 0xF0, 0x23, 0x00, 0xFC, 0x0F, 0xE0, 0x7F, 0x00, 0xFC, 0x03, 0x80, 0xFF, 0x01, 0xFC, 0x00, 0x00, 0x3E, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00}; */ -/* + #define USERPREFS_USE_ADMIN_KEY 1 -static unsigned char USERPREFS_ADMIN_KEY[] = {0xcd, 0xc0, 0xb4, 0x3c, 0x53, 0x24, 0xdf, 0x13, 0xca, 0x5a, 0xa6, - 0x0c, 0x0d, 0xec, 0x85, 0x5a, 0x4c, 0xf6, 0x1a, 0x96, 0x04, 0x1a, - 0x3e, 0xfc, 0xbb, 0x8e, 0x33, 0x71, 0xe5, 0xfc, 0xff, 0x3c}; -*/ +static unsigned char USERPREFS_ADMIN_KEY_0[] = {0xcd, 0xc0, 0xb4, 0x3c, 0x53, 0x24, 0xdf, 0x13, 0xca, 0x5a, 0xa6, + 0x0c, 0x0d, 0xec, 0x85, 0x5a, 0x4c, 0xf6, 0x1a, 0x96, 0x04, 0x1a, + 0x3e, 0xfc, 0xbb, 0x8e, 0x33, 0x71, 0xe5, 0xfc, 0xff, 0x3c}; +static unsigned char USERPREFS_ADMIN_KEY_1[] = {}; +static unsigned char USERPREFS_ADMIN_KEY_2[] = {}; + /* * USERPREF_FIXED_GPS_LAT and USERPREF_FIXED_GPS_LON must be set, USERPREF_FIXED_GPS_ALT is optional From 4b0fc47359495cdf55f78b6e80196a03b60461c6 Mon Sep 17 00:00:00 2001 From: gjelsoe <36234524+gjelsoe@users.noreply.github.com> Date: Fri, 15 Nov 2024 08:45:46 +0100 Subject: [PATCH 3/6] Update userPrefs.h Allows all 3 PKI keys to be added to userPrefs.h (#4969) --- userPrefs.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/userPrefs.h b/userPrefs.h index 24331d413..a0e82f199 100644 --- a/userPrefs.h +++ b/userPrefs.h @@ -28,13 +28,13 @@ // #define USERPREFS_CHANNEL_0_PRECISION 14 // #define USERPREFS_CHANNEL_0_UPLINK_ENABLED true // #define USERPREFS_CHANNEL_0_DOWNLINK_ENABLED true - +/* #define USERPREFS_CHANNEL_1_PSK \ { \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \ } - +*/ // #define USERPREFS_CHANNEL_1_NAME "REPLACEME" // #define USERPREFS_CHANNEL_1_PRECISION 14 // #define USERPREFS_CHANNEL_1_UPLINK_ENABLED true @@ -69,13 +69,19 @@ static unsigned char icon_bits[] = { 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00}; */ +/* + * PKI Admin keys. + * If a Admin key is set with 'static unsigned char USERPREFS_ADMIN_KEY_1[] = {};' then it will be ignored + * a PKI key must have a size of 32. + */ +/* #define USERPREFS_USE_ADMIN_KEY 1 static unsigned char USERPREFS_ADMIN_KEY_0[] = {0xcd, 0xc0, 0xb4, 0x3c, 0x53, 0x24, 0xdf, 0x13, 0xca, 0x5a, 0xa6, 0x0c, 0x0d, 0xec, 0x85, 0x5a, 0x4c, 0xf6, 0x1a, 0x96, 0x04, 0x1a, 0x3e, 0xfc, 0xbb, 0x8e, 0x33, 0x71, 0xe5, 0xfc, 0xff, 0x3c}; static unsigned char USERPREFS_ADMIN_KEY_1[] = {}; static unsigned char USERPREFS_ADMIN_KEY_2[] = {}; - +*/ /* * USERPREF_FIXED_GPS_LAT and USERPREF_FIXED_GPS_LON must be set, USERPREF_FIXED_GPS_ALT is optional From 65f91b8d14e64557d29bbdf83fd9f3d9a248f4ef Mon Sep 17 00:00:00 2001 From: gjelsoe <36234524+gjelsoe@users.noreply.github.com> Date: Sat, 16 Nov 2024 17:20:59 +0100 Subject: [PATCH 4/6] Update NodeDB.cpp Trunk --- src/mesh/NodeDB.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index d0b106f22..5119937ab 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -410,26 +410,26 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) // Initialize admin_key_count to zero byte numAdminKeys = 0; -// Check if USERPREFS_ADMIN_KEY_0 is non-empty -if (sizeof(USERPREFS_ADMIN_KEY_0) > 0) { - memcpy(config.security.admin_key[numAdminKeys].bytes, USERPREFS_ADMIN_KEY_0, 32); - config.security.admin_key[numAdminKeys].size = 32; - numAdminKeys++; -} + // Check if USERPREFS_ADMIN_KEY_0 is non-empty + if (sizeof(USERPREFS_ADMIN_KEY_0) > 0) { + memcpy(config.security.admin_key[numAdminKeys].bytes, USERPREFS_ADMIN_KEY_0, 32); + config.security.admin_key[numAdminKeys].size = 32; + numAdminKeys++; + } -// Check if USERPREFS_ADMIN_KEY_1 is non-empty -if (sizeof(USERPREFS_ADMIN_KEY_1) > 0) { - memcpy(config.security.admin_key[numAdminKeys].bytes, USERPREFS_ADMIN_KEY_1, 32); - config.security.admin_key[numAdminKeys].size = 32; - numAdminKeys++; -} + // Check if USERPREFS_ADMIN_KEY_1 is non-empty + if (sizeof(USERPREFS_ADMIN_KEY_1) > 0) { + memcpy(config.security.admin_key[numAdminKeys].bytes, USERPREFS_ADMIN_KEY_1, 32); + config.security.admin_key[numAdminKeys].size = 32; + numAdminKeys++; + } -// Check if USERPREFS_ADMIN_KEY_2 is non-empty -if (sizeof(USERPREFS_ADMIN_KEY_2) > 0) { - memcpy(config.security.admin_key[config.security.admin_key_count].bytes, USERPREFS_ADMIN_KEY_2, 32); - config.security.admin_key[config.security.admin_key_count].size = 32; - numAdminKeys++; -} + // Check if USERPREFS_ADMIN_KEY_2 is non-empty + if (sizeof(USERPREFS_ADMIN_KEY_2) > 0) { + memcpy(config.security.admin_key[config.security.admin_key_count].bytes, USERPREFS_ADMIN_KEY_2, 32); + config.security.admin_key[config.security.admin_key_count].size = 32; + numAdminKeys++; + } config.security.admin_key_count = numAdminKeys; #endif if (shouldPreserveKey) { From 108fb1f8092ea48e7ff70e9499b8fcbf3cc8adf3 Mon Sep 17 00:00:00 2001 From: gjelsoe <36234524+gjelsoe@users.noreply.github.com> Date: Sat, 16 Nov 2024 17:21:13 +0100 Subject: [PATCH 5/6] Update userPrefs.h Changed wording --- userPrefs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/userPrefs.h b/userPrefs.h index a0e82f199..622a491c3 100644 --- a/userPrefs.h +++ b/userPrefs.h @@ -71,8 +71,8 @@ static unsigned char icon_bits[] = { /* * PKI Admin keys. - * If a Admin key is set with 'static unsigned char USERPREFS_ADMIN_KEY_1[] = {};' then it will be ignored - * a PKI key must have a size of 32. + * If a Admin key is set with '{};' + * then it will be ignored, a PKI key must have a size of 32. */ /* #define USERPREFS_USE_ADMIN_KEY 1 From 4711eedf16b9312a6b3207cb8d9a7d416a532b7a Mon Sep 17 00:00:00 2001 From: gjelsoe <36234524+gjelsoe@users.noreply.github.com> Date: Sat, 16 Nov 2024 17:22:21 +0100 Subject: [PATCH 6/6] Create base64_to_hex.py A little tool for converting base64 PKI Keys to decoded byte that userPrefs.h can understand. --- bin/base64_to_hex.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 bin/base64_to_hex.py diff --git a/bin/base64_to_hex.py b/bin/base64_to_hex.py new file mode 100644 index 000000000..07c559b9e --- /dev/null +++ b/bin/base64_to_hex.py @@ -0,0 +1,33 @@ +import sys +import base64 + +def base64_to_hex_string(b64_string): + try: + # Decode the Base64 string to raw bytes + decoded_bytes = base64.b64decode(b64_string) + except Exception as e: + raise ValueError(f"Invalid Base64 input: {e}") + + # Check if the decoded result is exactly 32 bytes + if len(decoded_bytes) != 32: + raise ValueError("Decoded Base64 input must be exactly 32 bytes.") + + # Convert each byte to its hex representation + hex_values = [f"0x{byte:02x}" for byte in decoded_bytes] + + # Join the formatted hex values with commas + formatted_output = "{ " + ", ".join(hex_values) + " };" + return formatted_output + +if __name__ == "__main__": + # Check if a Base64 string was provided in command line arguments + if len(sys.argv) != 2: + print("Usage: python script.py ") + sys.exit(1) + + b64_string = sys.argv[1] + try: + formatted_hex = base64_to_hex_string(b64_string) + print(formatted_hex) + except ValueError as e: + print(e)