onlyn00bs-badge

OnlyN00bs: a DEF CON 34 friend-finder badge. ESP32 firmware, Web Bluetooth setup app, printable case
git clone https://git.virtualshack.io/onlyn00bs-badge.git
Log | Files | Refs | README | LICENSE

commit c6332401f3d63acc2608d28f3501998c2dd8b972
parent b963e2986d162adbec1fea3198b08c6e918e7257
Author: virtualtack <[email protected]>
Date:   Thu, 15 Oct 2026 03:29:04 +0000

firmware, web: snapshot of v1.10-11-g45f8c41

Changed, by area:
  firmware: 2 files
  web: 1 file

Diffstat:
MSNAPSHOT.md | 2+-
Mfirmware/src/config.h | 2+-
Mfirmware/src/secrets.h.example | 68+++++++++++++++++++++++++++++++++++++++++++++++---------------------
Mweb/src/update/index.html | 14+++++++++-----
4 files changed, 58 insertions(+), 28 deletions(-)

diff --git a/SNAPSHOT.md b/SNAPSHOT.md @@ -1,7 +1,7 @@ # About this snapshot This repository is the public release of the OnlyN00bs badge, taken from its private -development repo at `v1.10-9-gae1c317` on 2026-10-15. It holds what describes the **production unit +development repo at `v1.10-11-g45f8c41` on 2026-10-15. It holds what describes the **production unit as it is**: the firmware, the Web Bluetooth setup app, the site, the parts list, and the case. diff --git a/firmware/src/config.h b/firmware/src/config.h @@ -62,7 +62,7 @@ static const size_t GROUP_PSK_LEN = sizeof(GROUP_PSK); // omits GROUP_PSK_IS_PLACEHOLDER, so it passes; a missing secrets.h OR one still holding // the placeholder marker stops the build right here. #if defined(BADGE_PRODUCTION) && defined(GROUP_PSK_IS_PLACEHOLDER) -#error "Production build (oled_v3_prod) with the throwaway GROUP_PSK. Create firmware/src/secrets.h from secrets.h.example, set a real key (openssl rand -hex 32), and delete its GROUP_PSK_IS_PLACEHOLDER line. See the GROUP SECRET block in config.h." +#error "Production build (oled_v3_prod) with no group key. Copy firmware/src/secrets.h.example to firmware/src/secrets.h and paste the key into its GROUP_PSK_HEX line (steps are in that file)." #endif // Dev builds on the placeholder still work — but say so, loudly, every compile. diff --git a/firmware/src/secrets.h.example b/firmware/src/secrets.h.example @@ -1,32 +1,58 @@ #pragma once // ───────────────────────────────────────────────────────────────────────── -// secrets.h — the crew GROUP SECRET (HMAC key for beacon auth) +// secrets.h — the GROUP KEY (HMAC key for beacon auth) // -// THIS FILE (secrets.h.example) IS A TEMPLATE, TRACKED IN GIT. It holds only -// the public throwaway placeholder — it is NOT a real key. +// THIS FILE (secrets.h.example) IS A TEMPLATE, TRACKED IN GIT. It holds no key. +// Badges only see badges built with the same key. // -// To set the real crew key for a fleet flash, on the flashing machine: -// 1. cp firmware/src/secrets.h.example firmware/src/secrets.h -// (secrets.h is gitignored — it must never be committed) -// 2. openssl rand -hex 32 -// 3. paste those 32 bytes into GROUP_PSK below, in secrets.h -// 4. DELETE the GROUP_PSK_IS_PLACEHOLDER line at the bottom -// 5. store the same key in your password manager — it is unrecoverable, -// and every crew badge must flash the IDENTICAL key +// 1. cp firmware/src/secrets.h.example firmware/src/secrets.h +// (secrets.h is gitignored — it must never be committed) +// 2. In secrets.h, paste the key between the quotes on the GROUP_PSK_HEX line: +// • JOINING AN EXISTING GROUP (e.g. updating your badge): paste the key you +// were given. Do NOT generate one — a new key can't see anyone else's +// badge, and that shows up as "nobody in range", not as an error. +// • STARTING A NEW GROUP: generate one with openssl rand -hex 32 and keep +// it in a password manager. It is unrecoverable, and every badge in the +// group must be built with the IDENTICAL key. +// 3. Build with env oled_v3_prod. // -// Then build the fleet with env oled_v3_prod, which REFUSES to compile unless -// a real secrets.h (placeholder line removed) is present. See config.h. +// The key is 64 hex characters (0-9, a-f), no spaces or 0x. It's converted to +// bytes at compile time below, and a bad paste stops the build with a message. // ───────────────────────────────────────────────────────────────────────── #include <stdint.h> #include <stddef.h> -// REPLACE these 32 bytes with the output of `openssl rand -hex 32`. -static const uint8_t GROUP_PSK[] = { - 0xde,0xad,0xbe,0xef, 0x00,0x11,0x22,0x33, 0x44,0x55,0x66,0x77, 0x88,0x99,0xaa,0xbb, - 0xcc,0xdd,0xee,0xff, 0x13,0x37,0xc0,0xde, 0xfe,0xed,0xfa,0xce, 0xba,0xdc,0x0f,0xee -}; -static const size_t GROUP_PSK_LEN = sizeof(GROUP_PSK); +#define GROUP_PSK_HEX "" -#define GROUP_PSK_SET 1 // tells config.h a key was provided here +// ── nothing to edit below this line ────────────────────────────────────── + +namespace group_psk { +constexpr int nibble(char c) { + return (c >= '0' && c <= '9') ? c - '0' + : (c >= 'a' && c <= 'f') ? c - 'a' + 10 + : (c >= 'A' && c <= 'F') ? c - 'A' + 10 : -1; +} +template <size_t N> constexpr bool valid(const char (&s)[N]) { + if (N != 65) return false; // 64 hex chars + the string's NUL + for (size_t i = 0; i < 64; i++) if (nibble(s[i]) < 0) return false; + return true; +} +struct Key { uint8_t b[32]; }; +template <size_t N> constexpr Key parse(const char (&s)[N]) { + Key k{}; + if (valid(s)) + for (size_t i = 0; i < 32; i++) k.b[i] = uint8_t(nibble(s[2 * i]) << 4 | nibble(s[2 * i + 1])); + return k; +} +} // namespace group_psk + +static_assert(sizeof(GROUP_PSK_HEX) == 65, + "secrets.h: GROUP_PSK_HEX must be exactly 64 hex characters - paste the whole key between the quotes"); +static_assert(group_psk::valid(GROUP_PSK_HEX), + "secrets.h: GROUP_PSK_HEX may only contain 0-9 and a-f (no spaces, colons or 0x)"); -#define GROUP_PSK_IS_PLACEHOLDER 1 // ← DELETE this line once you set a real key above +static constexpr group_psk::Key GROUP_PSK_KEY = group_psk::parse(GROUP_PSK_HEX); +static const uint8_t* const GROUP_PSK = GROUP_PSK_KEY.b; +static const size_t GROUP_PSK_LEN = sizeof(GROUP_PSK_KEY.b); + +#define GROUP_PSK_SET 1 // tells config.h a key was provided here diff --git a/web/src/update/index.html b/web/src/update/index.html @@ -58,7 +58,7 @@ <li><b>PlatformIO Core:</b> <code>pipx install platformio</code> (or <code>pip install platformio</code> i guess) The ESP32 toolchain downloads on first build.</li> - <li><b>The group key file, <code>secrets.h</code></b>, ask virtualtack for it. Without it + <li><b>The group key</b> (64 letters and numbers), ask virtualtack for it. Without it your badge will stop seeing everyone else's.</li> <li><b>The USB driver</b> for the badge's CH340 serial chip: <ul> @@ -87,9 +87,12 @@ <li>Clone the source: <pre><code>git clone https://git.virtualshack.io/onlyn00bs-badge.git cd onlyn00bs-badge</code></pre></li> - <li>Copy the <code>secrets.h</code> you were sent to <code>firmware/src/secrets.h</code>.</li> + <li>Create the key file from its template: +<pre><code>cp firmware/src/secrets.h.example firmware/src/secrets.h</code></pre> + Open <code>firmware/src/secrets.h</code> and paste the key between the quotes on the + <code>#define GROUP_PSK_HEX ""</code> line.</li> <li>Check it is the right key. This prints a fingerprint of the key without revealing it: -<pre><code>python3 -c 'import re,hashlib;b=open("firmware/src/secrets.h").read().split("GROUP_PSK[] = {")[1].split("};")[0];print(hashlib.sha256(bytes(int(x,16) for x in re.findall(r"0x([0-9a-fA-F]{2})",b))).hexdigest()[:16])'</code></pre> +<pre><code>python3 -c 'import re,hashlib;k=re.search(r"#define GROUP_PSK_HEX \"(.*)\"",open("firmware/src/secrets.h").read()).group(1);print(hashlib.sha256(bytes.fromhex(k)).hexdigest()[:16])'</code></pre> It must print <code>a4dc586d0276fa51</code>. Anything else means the wrong file: stop and ask for the right one.</li> </ol> @@ -156,8 +159,9 @@ cd onlyn00bs-badge</code></pre></li> <dt><code>Permission denied</code> on the port (Linux)</dt> <dd>Add yourself to <code>dialout</code> and log out and back in.</dd> <dt>Build fails with an error about the group key</dt> - <dd><code>secrets.h</code> is missing or in the wrong place. It must be at - <code>firmware/src/secrets.h</code>.</dd> + <dd><code>secrets.h</code> is missing, in the wrong place, or the key isn't pasted in + whole. It must be at <code>firmware/src/secrets.h</code>, with all 64 characters of the + key between the quotes and nothing else.</dd> <dt><code>Failed to connect to ESP32</code></dt> <dd>Unplug, replug, and run the command again. Close any serial monitor that has the port open.</dd>