Skip to content

Commit 8e85adc

Browse files
1technophileclaude
andcommitted
[BT] Default BLE AES key empty, skip decryption without a key
Shipping a non-empty default key caused fresh installs to attempt decryption of every encrypted PVVX/BTHome v2/Victron advertisement with the placeholder string from User_config.h. Frames that didn't happen to share that key were silently dropped at the CCM auth step, masking otherwise-decodable devices (notably Victron MPPT) until users found and entered a per-MAC key. Initialise ble_aes[] to "" and treat an empty default as "no default configured" in the decryption path - mirroring Theengs Gateway, which has no default and skips frames whose MAC has no bindkey. Per-MAC keys in ble_aes_keys still take precedence; the BLE_AES macro remains as the WebUI placeholder hint. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 079c987 commit 8e85adc

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

main/User_config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,8 @@ void storeSignalValue(uint64_t);
695695
# define JSON_BLE_AES_CUSTOM_KEYS 256 // 42 byte BLE Custom Key * 6 rounded up to 256.
696696
# endif
697697
# ifndef BLE_AES
698-
# define BLE_AES "00112233445566778899001122334455"
698+
# define BLE_AES "" // Runtime default for ble_aes[]. Empty = no default; override
699+
// at build time with -DBLE_AES='"<32-hex-key>"' to ship one.
699700
# endif
700701
# endif
701702
#endif

main/config_WebContent.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ const char config_ble_body_decoder[] =
294294
const char config_ble_body_encrypt[] =
295295
"<hr><p><b>Encryption</b></p>"
296296
"<p><b>BLE AES Default Key (32 char hex)</b></p>"
297-
"<input id='bk' name='bk' minlength='32' maxlength='32' placeholder=" BLE_AES
298-
" value='%s'>"
297+
"<input id='bk' name='bk' minlength='32' maxlength='32' placeholder='00112233445566778899001122334455' value='%s'>"
299298
"<hr><p><b>BLE Key Pairs</b></p>"
300299
"<p>MacAddress:AESKey with space separator</p>"
301300
"<p><textarea id='kp' name='kp' placeholder='A4C138012345:00112233445566778899001122334455' rows='3' cols='46'>%s</textarea></p>";

main/gatewayBT.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,9 +1275,14 @@ void process_bledata(JsonObject& BLEdata) {
12751275
if (ble_aes_keys.containsKey(macWOdots)) {
12761276
THEENGS_LOG_TRACE(F("[BLEDecryptor] Custom AES key %s" CR), ble_aes_keys[macWOdots].as<const char*>());
12771277
bleaeskeylength = hexToBytes(ble_aes_keys[macWOdots], bleaeskey, 16);
1278-
} else {
1278+
} else if (strlen(ble_aes) >= 32) {
12791279
THEENGS_LOG_TRACE(F("[BLEDecryptor] Default AES key" CR));
12801280
bleaeskeylength = hexToBytes(ble_aes, bleaeskey, 16);
1281+
} else {
1282+
// No per-MAC key configured and no default set: skip silently rather
1283+
// than attempting decryption with a placeholder key.
1284+
THEENGS_LOG_DEBUG(F("[BLEDecryptor] No AES key configured for %s, skipping" CR), macWOdots.c_str());
1285+
return;
12811286
}
12821287
// Check AES Key
12831288
if (bleaeskeylength != 16) {

main/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ char gateway_name[parameters_size + 1] = Gateway_Name;
9696
unsigned long lastDiscovery = 0;
9797

9898
#if BLEDecryptor
99+
// BLE_AES defaults to "" (see User_config.h) so encrypted PVVX/BTHome/Victron
100+
// frames are only decrypted when a per-MAC key is configured (ble_aes_keys) or
101+
// the user enters a default. Sites shipping a stock default key can still set
102+
// it at build time via -DBLE_AES='"<32-hex-key>"'.
99103
char ble_aes[parameters_size] = BLE_AES;
100104
StaticJsonDocument<JSON_BLE_AES_CUSTOM_KEYS> ble_aes_keys;
101105
#endif

0 commit comments

Comments
 (0)