Skip to content

Allow multiple keyspecs in one environment variable

Jonas Rebmann barebox 4 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected] change-id 20260206-keytoc-multi-env-4a3300292e4a

Versions newest first

  1. v4 Latest8 patches 1 replyApplied
  2. v34 patches 4 repliesSuperseded
  3. v22 patches 2 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v1 RFC1 patch2 repliesSuperseded

Changes in v4 from the cover letter · 16 lines

- split out two more preparatory patches
- add patch to remove handling of fit-hint env variables
- add patch to fix handling of fit-hint env variables
- drop unneeded strdup of argv (Thanks, Marco)
- const buffer holding getenv result to prevent modification of
environment variable (Thanks, Marco)
- adapt commit message to explain why keyspec list is looped before
writing stdout
- fix bug where hint and path are only expanded when keyspec is provided
via env variable. Instead move expansion and validation into yet
another loop over the keyspecs
- error out on empty/undefined environment variable keyspec
- fix potential out of bounds when indexing argv with listi
- use listi index variable when re-interating keys list instead of
using argi variable earlier used when iterating both keys and args
- Link to v3: https://lore.barebox.org/barebox/[email protected]

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/8scripts: include: Add string_util.h for strsep_unescapedscripts/include/string_util.h+65 -00 replies
2/8crypto: keytoc: Improve readabilityscripts/keytoc.c+13 -120 replies
3/8crypto: keytoc: Move special handling of legacy pkcs11 format to parse_keyspecscripts/keytoc.c+8 -70 replies
4/8crypto: keytoc: Parse all keyspecs before writing to stdoutscripts/keytoc.c+22 -200 replies
5/8crypto: keytoc: Split env-provided full keyspec on spacesscripts/keytoc.c+48 -120 replies
6/8Documentation: migration-guides: Document change in keyspec env varsDocumentation/migration-guides/migration-master.rst+17 -00 replies
7/8crypto: keytoc: Allow fields to start with underscorescripts/keytoc.c+2 -20 replies
8/8crypto: keytoc: Deprecate fit-hint from env variableDocumentation/migration-guides/migration-master.rst crypto/Kconfig scripts/keytoc.c+10 -80 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 0/8] Allow multiple keyspecs in one environment variable

This contains the actual change to keytoc as well a migration Note.

Allowing any number of public keys to be provided via a single environment variable eases integration in more complex setups where multiple public keys per keyring are managed externally.

During testing, it was found that handling of fit-hint env variables was broken since 2025.12. Since this is a legacy feature this series includes a patch that fixes the bug in the handling of fit-hint env variables as well as a patch that removes the feature.

Before removal of the feature, the following tests where performed and keytoc output was manually verified:

cd scripts/
gcc -g keytoc.c $(pkg-config --libs --cflags openssl) -o keytoc export rsakey="../crypto/snakeoil-4096-development.pem" export ecdsakey="../crypto/snakeoil-ecdsa-development.pem" export fullspec="keyring=fit,fit-hint=__ENV__hint:$ecdsakey" export triplekey="$rsakey $ecdsakey $fullspec"

export hint=test

diff -q <(./keytoc $ecdsakey) <(./keytoc __ENV__ecdsakey)
diff -q <(./keytoc $rsakey) <(./keytoc __ENV__rsakey)
diff -q <(./keytoc $fullspec) <(./keytoc __ENV__fullspec)
diff -q <(./keytoc __ENV__triplekey __ENV__ecdsakey __ENV__triplekey) <(./keytoc $triplekey $ecdsakey $triplekey)

---
Changes in v4:
- split out two more preparatory patches
- add patch to remove handling of fit-hint env variables
- add patch to fix handling of fit-hint env variables
- drop unneeded strdup of argv (Thanks, Marco)
- const buffer holding getenv result to prevent modification of
environment variable (Thanks, Marco)
- adapt commit message to explain why keyspec list is looped before
writing stdout
- fix bug where hint and path are only expanded when keyspec is provided
via env variable. Instead move expansion and validation into yet
another loop over the keyspecs
- error out on empty/undefined environment variable keyspec
- fix potential out of bounds when indexing argv with listi
- use listi index variable when re-interating keys list instead of
using argi variable earlier used when iterating both keys and args
- Link to v3: https://lore.barebox.org/barebox/[email protected]

Changes in v3:
- Where possible, split refactoring/cleanup into a preparatory commit
- Split copying strsep_unescape into a separate commit
- Link to v2: https://lore.barebox.org/barebox/[email protected]

Changes in v2:
- Split up the keyspec environment variables when multiple are provided
too.
- Use strsep_unescape instead of manual split/unescape
- Remove RFC tag
- Link to v1: https://lore.barebox.org/barebox/[email protected]

---
Jonas Rebmann (8):
scripts: include: Add string_util.h for strsep_unescaped
crypto: keytoc: Improve readability
crypto: keytoc: Move special handling of legacy pkcs11 format to parse_keyspec
crypto: keytoc: Parse all keyspecs before writing to stdout
crypto: keytoc: Split env-provided full keyspec on spaces
Documentation: migration-guides: Document change in keyspec env vars
crypto: keytoc: Allow fields to start with underscore
crypto: keytoc: Deprecate fit-hint from env variable

 .../migration-guides/migration-master.rst          |  21 ++++
 crypto/Kconfig                                     |   7 +-
 scripts/include/string_util.h                      |  65 ++++++++++++
 scripts/keytoc.c                                   | 113 ++++++++++++++-------
 4 files changed, 165 insertions(+), 41 deletions(-)

---
base-commit: ff814eff55e898037503e942df8e0ba8f1b13222
change-id: 20260206-keytoc-multi-env-4a3300292e4a

Best regards,

Signature · 1 line
Jonas Rebmann <[email protected]>