[PATCH 00/14] Keep PSKs on a PKCS#11 token

Angelo Compagnucci angelo.compagnucci at gmail.com
Mon Nov 23 06:24:34 PST 2026


The EU Cyber Resilience Act (Regulation (EU) 2024/2847) asks products
with digital elements sold in the EU to protect the data they store,
for example by encrypting it (Annex I, Part I, point 2(e)). For a
device that uses wpa_supplicant, this means secrets such as a network
PSK should not be stored in clear text. Today the configuration file
and the external password backends store them in clear text.

With this series, wpa_supplicant can keep network PSKs, or any other
external password, on a PKCS#11 token such as a TPM or a TEE based
token. The configuration file then has only psk=ext:<name>.

1: SAVE_CONFIG removed WPA-PSK and SAE networks with psk=ext:<name>,
   because they have no password in the file. This fix is independent
   of the rest.
2-3: preparation. CONFIG_TLS_ENGINE_TRUSTED_PATH did nothing, because
   it was not passed to the compiler. Also, the check it enables did
   not compile. The check moves to os_unix.c so it can be shared.
   Patch 2 is an independent fix.
4: D-Bus put quotes around every psk string, so a client such as a GUI
   could not set psk=ext:<name>. Also an independent fix.
5-7: a "pkcs11" backend based on p11-kit. It reads passwords from data
   objects (CKO_DATA). The label (CKA_LABEL) is the password name. A
   PKCS#11 URI (RFC 7512) selects the token. Like other p11-kit users,
   it looks in the registered modules, unless module-path or
   pkcs11_module_path names a module. With
   CONFIG_TLS_ENGINE_TRUSTED_PATH, module-path is checked. The PIN
   comes from pin-value or from a pin-source file.
8-9: an optional set operation for external password backends, used
   by the pkcs11 backend.
10: with the pkcs11 backend, saving the configuration stores a new
   passphrase or PSK of a psk=ext:<name> network on the token, where
   SAVE_CONFIG would write it to the file. Other backends save as
   before:

     SET_NETWORK 0 psk "new passphrase"
     SAVE_CONFIG          (stored on the token, file keeps psk=ext:...)

11-14: hwsim tests. Patches 11 and 12 test the fixes of patches 1 and 4
   with the test backend. Patch 13 builds the pkcs11 backend in the test
   configuration, and patch 14 tests it with SoftHSM.

How the module is selected (RFC 7512):
1. module-path in the URI: load only this library. With
   CONFIG_TLS_ENGINE_TRUSTED_PATH, it must pass os_lib_path_trusted()
   first, because loading code named in a URI needs care (RFC 7512,
   section 6).
2. Otherwise, pkcs11_module_path. Patch 7 adds it to the URI as
   module-path, so the EAP-TLS setting is reused.
3. Otherwise, the registry. Look in all modules registered with
   p11-kit, or only in the one named by module-name, like other p11-kit
   users.
In all cases only the selected modules are searched, and the token,
slot and library attributes of the URI still select the token. If the
URI has both module-path and module-name, which RFC 7512 says SHOULD be
avoided, no module matches.

Tested with three tokens: SoftHSM 2.6.1 on x86_64, the OP-TEE PKCS#11 TA
(libckteec) on an STM32MP133, and tpm2-pkcs11 on an Infineon SLB9670 TPM
2.0 on an STM32MP157. On both boards SAVE_CONFIG stored the passphrase
as a private object that cannot be seen without the PIN. The station
connected to a WPA2-PSK AP with the PSK read from the token, also after
a second save replaced it. tpm2-pkcs11 accepts an in-place update of
CKA_VALUE but loses the value, so the backend always creates a new
object and then destroys the old one. The registered modules,
module-name and pkcs11_module_path were tested with SoftHSM, and
pkcs11_module_path also with tpm2-pkcs11. The D-Bus path (psk
"ext:<name>", SaveConfig) was tested on both boards. Each patch builds
on its own, with and without CONFIG_TLS_ENGINE_TRUSTED_PATH, with the
D-Bus interface, and cross built for the boards.

The new hwsim tests pass in a UML VM. The existing ext_password,
wpas_config and D-Bus tests still pass, except two D-Bus NAN tests
(dbus_nan_usd_subscribe_followup and dbus_nan_usd_publish_followup) that
fail the same way without this series.

Angelo Compagnucci (14):
  wpa_supplicant: keep networks with an external PSK in the saved config
  OpenSSL: make CONFIG_TLS_ENGINE_TRUSTED_PATH work
  utils: move the trusted path check of the OpenSSL engines to os_unix.c
  dbus: allow psk=ext:<name> in network properties
  ext_password: add a PKCS#11 token backend
  ext_password_pkcs11: read the PIN from a file
  ext_password_pkcs11: default to the PKCS#11 module of EAP-TLS
  ext_password: add an operation to store a password
  ext_password_pkcs11: store passwords
  wpa_supplicant: store external PSKs when saving the configuration
  tests: SAVE_CONFIG with an external PSK
  tests: D-Bus network with an external PSK
  tests: build the pkcs11 external password backend
  tests: pkcs11 external password backend with SoftHSM

 doc/ctrl_iface.doxygen                    |   5 +
 src/crypto/tls_openssl.c                  |  80 +---
 src/utils/ext_password.c                  |  24 +
 src/utils/ext_password.h                  |   3 +
 src/utils/ext_password_i.h                |   5 +
 src/utils/ext_password_pkcs11.c           | 510 ++++++++++++++++++++++
 src/utils/os.h                            |  23 +
 src/utils/os_unix.c                       |  60 +++
 tests/hwsim/example-wpa_supplicant.config |   1 +
 tests/hwsim/test_dbus.py                  |  20 +
 tests/hwsim/test_ext_password.py          | 306 +++++++++++++
 wpa_supplicant/Android.mk                 |   4 +
 wpa_supplicant/Makefile                   |  17 +
 wpa_supplicant/config_file.c              |   4 +-
 wpa_supplicant/ctrl_iface.c               |   8 +
 wpa_supplicant/dbus/dbus_new_handlers.c   |  20 +-
 wpa_supplicant/defconfig                  |   8 +-
 wpa_supplicant/wpa_supplicant.c           | 120 ++++-
 wpa_supplicant/wpa_supplicant.conf        |  33 ++
 wpa_supplicant/wpa_supplicant_i.h         |   3 +
 20 files changed, 1172 insertions(+), 82 deletions(-)
 create mode 100644 src/utils/ext_password_pkcs11.c

-- 
2.53.0




More information about the Hostap mailing list