Skip to content

Commit aadf2a6

Browse files
committed
Peer review fixes (thanks Copilot)
1 parent 3bbf27b commit aadf2a6

6 files changed

Lines changed: 301 additions & 71 deletions

File tree

configure.ac

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,25 @@ then
531531
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_BROKER_PERSIST_ENCRYPT"
532532
fi
533533

534+
# Development-only fixed-pattern derive_key hook for the CLI broker.
535+
# Off by default; required to use "-E dev" on encrypt builds. Never
536+
# enable in a production build - the resulting binary contains a
537+
# trivially-recoverable AES-GCM key generator that any flip of the
538+
# CLI argument would substitute for real key management.
539+
AC_ARG_ENABLE([broker-persist-encrypt-dev-key],
540+
[AS_HELP_STRING([--enable-broker-persist-encrypt-dev-key],[Link the CLI broker's fixed-pattern "dev" derive_key hook (default: disabled; requires --enable-broker-persist-encrypt; NOT FOR PRODUCTION)])],
541+
[ ENABLED_BROKER_PERSIST_ENCRYPT_DEV_KEY=$enableval ],
542+
[ ENABLED_BROKER_PERSIST_ENCRYPT_DEV_KEY=no ]
543+
)
544+
if test "x$ENABLED_BROKER_PERSIST_ENCRYPT_DEV_KEY" = "xyes"
545+
then
546+
if test "x$ENABLED_BROKER_PERSIST_ENCRYPT" != "xyes"
547+
then
548+
AC_MSG_ERROR([--enable-broker-persist-encrypt-dev-key requires --enable-broker-persist-encrypt])
549+
fi
550+
AM_CFLAGS="$AM_CFLAGS -DWOLFMQTT_BROKER_PERSIST_ENCRYPT_DEV_KEY"
551+
fi
552+
534553

535554
AM_CONDITIONAL([HAVE_LIBWOLFSSL], [test "x$ENABLED_TLS" = "xyes"])
536555
AM_CONDITIONAL([HAVE_LIBCURL], [test "x$ENABLED_CURL" = "xyes"])

scripts/broker.test

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,22 @@ echo "$broker_features" | grep -q " persist" && has_persist=yes
170170
has_persist_encrypt=no
171171
echo "$broker_features" | grep -q " persist-encrypt" && \
172172
has_persist_encrypt=yes
173+
has_persist_encrypt_dev_key=no
174+
echo "$broker_features" | grep -q " persist-encrypt-dev-key" && \
175+
has_persist_encrypt_dev_key=yes
173176
has_static_memory=no
174177
echo "$broker_features" | grep -q " static-memory" && \
175178
has_static_memory=yes
176179

177180
# Persist-encrypt builds refuse to start without an explicit key source.
178181
# CLI tests opt into the development key with -E dev (NOT for production
179-
# - the key is a fixed pattern in the binary). For non-encrypt builds
180-
# this stays empty so the unknown -E option doesn't trigger usage.
182+
# - the key is a fixed pattern in the binary, only linked into the
183+
# binary when --enable-broker-persist-encrypt-dev-key was passed at
184+
# configure time). For non-encrypt builds and encrypt builds without
185+
# the dev-key hook this stays empty; the encrypt-CLI tests check the
186+
# capability flag explicitly and SKIP when missing.
181187
broker_dir_flags=""
182-
if [ "$has_persist_encrypt" = "yes" ]; then
188+
if [ "$has_persist_encrypt_dev_key" = "yes" ]; then
183189
broker_dir_flags="-E dev"
184190
fi
185191

@@ -1214,6 +1220,9 @@ elif [ "$has_persist" = "no" ]; then
12141220
echo "SKIP: Persist round-trip (built without --enable-broker-persist)"
12151221
elif [ "$has_retained" = "no" ]; then
12161222
echo "SKIP: Persist round-trip (retained support not built)"
1223+
elif [ "$has_persist_encrypt" = "yes" ] && \
1224+
[ "$has_persist_encrypt_dev_key" = "no" ]; then
1225+
echo "SKIP: Persist round-trip (encrypt build without dev-key CLI hook)"
12171226
else
12181227
T27_DIR="${TMP_DIR}/persist_t27"
12191228
mkdir -p "$T27_DIR"
@@ -1259,10 +1268,18 @@ wait $T27_SUB_PID 2>/dev/null || true
12591268
TEST_PIDS=()
12601269
T27_GOT=no
12611270
grep -q "t27_payload" "${TMP_DIR}/t27_sub.log" 2>/dev/null && T27_GOT=yes
1271+
# On encrypt builds broker_dir_flags includes -E dev, so T27 ends up
1272+
# exercising the encrypted-at-rest round-trip too (T31 still adds the
1273+
# specific no-plaintext-on-disk check). Annotate so the log is honest
1274+
# about what was covered.
1275+
T27_MODE="plaintext"
1276+
if [ "$has_persist_encrypt_dev_key" = "yes" ]; then
1277+
T27_MODE="encrypted via -E dev"
1278+
fi
12621279
if [ "$T27_GOT" = "yes" ] && [ "$T27_RESTORED" = "yes" ]; then
1263-
echo "PASS: Persist round-trip (restored=$T27_RESTORED delivered=$T27_GOT)"
1280+
echo "PASS: Persist round-trip ($T27_MODE; restored=$T27_RESTORED delivered=$T27_GOT)"
12641281
else
1265-
echo "FAIL: Persist round-trip (restored=$T27_RESTORED delivered=$T27_GOT)"
1282+
echo "FAIL: Persist round-trip ($T27_MODE; restored=$T27_RESTORED delivered=$T27_GOT)"
12661283
FAIL=1
12671284
fi
12681285
fi # has_persist + has_retained
@@ -1291,6 +1308,11 @@ mkdir -p "$T28_DIR/1"
12911308
# Write a fake META file with a bogus schema version. Magic "WMQB",
12921309
# then schema_ver = 0xFFFF (big endian), rec_kind = 1, body_len = 4,
12931310
# body = some bytes.
1311+
# Filename "00.bin" reflects the POSIX backend's key-to-filename
1312+
# encoding: META uses a single 0x00 key byte, which wmqb_hex_encode
1313+
# (in src/mqtt_broker_persist_posix.c) renders as two lowercase hex
1314+
# chars - "00". If that encoding ever changes, update this filename
1315+
# to match.
12941316
printf 'WMQB\xff\xff\x00\x01\x00\x00\x00\x04zzzz' > "$T28_DIR/1/00.bin"
12951317
if [ $broker_pid != $no_pid ]; then
12961318
kill $broker_pid 2>/dev/null
@@ -1328,6 +1350,9 @@ elif [ "$has_persist" = "no" ]; then
13281350
echo "SKIP: Offline queue (built without --enable-broker-persist)"
13291351
elif [ "$has_static_memory" = "yes" ]; then
13301352
echo "SKIP: Offline queue (orphan/outbound-queue is dynamic-memory only)"
1353+
elif [ "$has_persist_encrypt" = "yes" ] && \
1354+
[ "$has_persist_encrypt_dev_key" = "no" ]; then
1355+
echo "SKIP: Offline queue (encrypt build without dev-key CLI hook)"
13311356
else
13321357
T29_DIR="${TMP_DIR}/persist_t29"
13331358
mkdir -p "$T29_DIR"
@@ -1399,6 +1424,9 @@ elif [ "$has_persist" = "no" ]; then
13991424
echo "SKIP: Offline queue restart (built without --enable-broker-persist)"
14001425
elif [ "$has_static_memory" = "yes" ]; then
14011426
echo "SKIP: Offline queue restart (orphan/outbound-queue is dynamic-memory only)"
1427+
elif [ "$has_persist_encrypt" = "yes" ] && \
1428+
[ "$has_persist_encrypt_dev_key" = "no" ]; then
1429+
echo "SKIP: Offline queue restart (encrypt build without dev-key CLI hook)"
14021430
else
14031431
T30_DIR="${TMP_DIR}/persist_t30"
14041432
mkdir -p "$T30_DIR"
@@ -1474,6 +1502,8 @@ if [ "$skip_plain" = "yes" ]; then
14741502
echo "SKIP: AES-GCM persist (plain listener disabled)"
14751503
elif [ "$has_persist_encrypt" = "no" ]; then
14761504
echo "SKIP: AES-GCM persist (built without --enable-broker-persist-encrypt)"
1505+
elif [ "$has_persist_encrypt_dev_key" = "no" ]; then
1506+
echo "SKIP: AES-GCM persist (built without --enable-broker-persist-encrypt-dev-key)"
14771507
elif [ "$has_retained" = "no" ]; then
14781508
echo "SKIP: AES-GCM persist (retained support not built)"
14791509
else

0 commit comments

Comments
 (0)