Skip to content

Commit 92a5ba6

Browse files
committed
initrd/gpg: address PR #2158 review comments
- Fix 6 instances of $? clobbered by intervening TRACE_FUNC/DEBUG calls: capture rc=$? immediately after each DO_WITH_DEBUG gpg pipeline, check $rc (adds local rc declarations). - Replace --passphrase-file with --passphrase-fd 3 3< <(...) to avoid leaking the PIN value through /proc/<pid>/cmdline of the child echo process (3 sites: factory reset, card identity, import). - Fix algo_code/bit_len extraction: add head -1 to prevent multi-line values when multiple keys are present in the backup. - Fix STATUS_OK on public partition mount: only emit on success. - Fix gpg_reset_nk3_secret_app: return actual hotp_verification error code, add local error_code, explicit return 0 for non-NK3. - Remove incorrect || [ $? -eq 2 ] pattern: gpg --import exit code 2 is a fatal error, not "unchanged". - Fix pubkey.asc import: check success properly, fall back to keyring export on failure. - Fix partition derivation for NVMe/MMC: use [0-9]+$ without (p?) capture that was removing the p separator. - Add _luks_cleanup helper called on every error return path to close LUKS mappings (removed broken EXIT trap). - Re-run NK3 Secrets app reset with custom PIN when factory reset is retried from default to custom PIN. - Add chmod 600 on /tmp/secret/gpg_pin to match existing convention. - Fix recovery-shell.md: gpg_auth also guards USB/external boot entry via media-scan.sh. - Write backup passphrase to /tmp/secret/backup_pass, call mount-usb.sh with --pass-file instead of --pass to avoid argv leak. - Add --pass-file option to mount-usb.sh (reads passphrase from file). - Fix doc/qemu.md: clarify ./qemu_img/ vs ~/Qemu_img/ roles. Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent 606d71d commit 92a5ba6

4 files changed

Lines changed: 153 additions & 45 deletions

File tree

doc/qemu.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,22 @@ cp -alf ~/Qemu_img/usb_fd.img \
158158

159159
### Daily development cycle
160160

161-
After OS install + USB provisioned, reference both from `./qemu_img/`:
161+
After OS install + USB provisioned, reference the root disk from `./qemu_img/`
162+
(inside the repo clone — Docker visibility) and USB backups from `~/Qemu_img/`
163+
(outside the repo — survives clean builds via hardlinks):
162164

163-
./docker_repro.sh make BOARD=qemu-coreboot-fbwhiptail-tpm1-hotp \
164-
PUBKEY_ASC=pubkey.asc \
165-
USB_TOKEN=Nitrokey3NFC \
166-
ROOT_DISK_IMG=./qemu_img/root.qcow2 \
167-
inject_gpg run
165+
```bash
166+
./docker_repro.sh make BOARD=qemu-coreboot-fbwhiptail-tpm1-hotp \
167+
PUBKEY_ASC=pubkey.asc \
168+
USB_TOKEN=Nitrokey3NFC \
169+
ROOT_DISK_IMG=./qemu_img/root.qcow2 \
170+
inject_gpg run
171+
```
172+
173+
Root disk images live at `./qemu_img/` because `ROOT_DISK_IMG` is passed to
174+
`make` inside the Docker container, which only sees `$(pwd)`. USB backup
175+
images live at `~/Qemu_img/` and are bridged into the build directory via
176+
hardlinks (`cp -alf`).
168177

169178

170179
### Testing GPG key reprovision from a backup drive

doc/recovery-shell.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ with the in-memory backup path, or by running the reprovision flow from the GPG
2727
Management Menu), the recovery shell requires GPG smartcard authentication before
2828
the bash prompt opens.
2929

30-
**Scope:** This ONLY guards recovery shell entry. USB boot, TPM operations,
30+
**Scope:** This guards recovery shell and external media/USB boot entry
31+
(`media-scan.sh` also calls `gpg_auth` before scanning USB). TPM operations,
3132
flash/update, GPG management, and all other GUI menu functions are NOT gated
3233
by this check — they remain accessible from the main menu.
3334

initrd/bin/mount-usb.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ DEVICE=""
2525
MOUNTPOINT="/media"
2626
PASS=""
2727

28-
#Only assign --mode, --device, --mountpoint and --pass parameters only if variables following them are not empty
28+
#Only assign --mode, --device, --mountpoint, --pass and --pass-file parameters
2929
while [ $# -gt 0 ]; do
3030
case "$1" in
3131
--mode)
@@ -56,6 +56,13 @@ while [ $# -gt 0 ]; do
5656
shift
5757
fi
5858
;;
59+
--pass-file)
60+
if [ -n "$2" ] && [ -r "$2" ]; then
61+
PASS="$(cat "$2")"
62+
shift
63+
shift
64+
fi
65+
;;
5966
*)
6067
usage
6168
exit 1

0 commit comments

Comments
 (0)