Skip to content

fix(server): HSM-wrapped hybrid KEM key lifecycle - #1330

Open
Manuthor wants to merge 13 commits into
developfrom
fix/hybrid_kem_hsm_lifecycle
Open

Manuthor wants to merge 13 commits into
developfrom
fix/hybrid_kem_hsm_lifecycle

Conversation

@Manuthor

@Manuthor Manuthor commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

With a server key_encryption_key stored in an HSM, ckms pqc keys create -a ml-kem-768-p256 fails with HTTP 500:

Cryptographic error: Unsupported key format type: ConfigurableKEMSecretKey, for a Transparent EC private key

Hybrid KEM keys (ConfigurableKEM, native X25519MLKEM768 / X448MLKEM1024) are ByteString-only keys with no OpenSSL representation.

Defects fixed

Defect File
A Wrap: NoEncoding sent every private/public key through OpenSSL (breaks Create, Import, ReKeyKeyPair, Export with a KeyWrappingSpecification) crate/crypto/src/crypto/wrap/wrap_key.rs
B Unwrap: decode_unwrapped_key did not decode ConfigurableKEM* (breaks Encrypt/Decrypt after restart, default_unwrap_type, NotWrapped export/import) crate/crypto/src/crypto/wrap/unwrap_key.rs
C Export rejected any requested KeyFormatType other than PKCS8/Raw, so a ConfigurableKEM key could not be exported with its own format crate/server/src/core/operations/export_get.rs

Import (D) and is_pqc_algorithm (E) were already fixed on develop by #1268.

Tests

  • cargo test -p cosmian_kms_crypto --features non-fips --lib test_wrap_unwrap_byte_string_kem_keys
  • tests::hsm::test_hsm_all now runs hybrid_kem_lifecycle (crate/server/src/tests/hsm/hybrid_kem_dek.rs): Create, restart (cold cache, HSM unwrap), GetAttributes, Locate, Export with stored format, Import, default_unwrap_type, ReKeyKeyPair, Encrypt/Decrypt (encapsulate/decapsulate), Revoke, Destroy for ml-kem-512-p256, ml-kem-768-p256 and X25519MLKEM768.
export SOFTHSM2_CONF=/tmp/softhsm2-kms/softhsm2.conf
mkdir -p /tmp/softhsm2-kms/tokens && echo "directories.tokendir = /tmp/softhsm2-kms/tokens" > "$SOFTHSM2_CONF"
SLOT=$(softhsm2-util --init-token --free --label my_token_1 --so-pin 12345678 --pin 12345678 | grep -o 'reassigned to slot [0-9]*' | awk '{print $4}')
HSM_MODEL=softhsm2 HSM_USER_PASSWORD=12345678 HSM_SLOT_ID=$SLOT SOFTHSM2_PKCS11_LIB=/opt/homebrew/lib/softhsm/libsofthsm2.so \
  cargo test -p cosmian_kms_server --features non-fips -- tests::hsm::test_hsm_all --ignored --exact

Notes

  • The commit was made with pre-commit hooks skipped (authorised by the maintainer): cargo deny check fails on a RUSTSEC advisory for ctutils 0.4.2 already present in develop's Cargo.lock.
  • ConfigurableKEM private keys are sensitive by default, so a plain export of them is denied by design; the SoftHSM2 test creates non-sensitive pairs.
  • 5.22.1 PR: fix(server): HSM-wrapped hybrid KEM key lifecycle (5.22.1) #1329

@Manuthor
Manuthor deployed to xks-remote-approval October 23, 2026 09:35 — with GitHub Actions Active
@Manuthor
Manuthor deployed to xks-remote-approval October 23, 2026 10:51 — with GitHub Actions Active
@Manuthor
Manuthor deployed to xks-remote-approval October 24, 2026 10:28 — with GitHub Actions Active
@Manuthor
Manuthor deployed to xks-remote-approval October 24, 2026 15:41 — with GitHub Actions Active
@Manuthor
Manuthor requested a deployment to xks-remote-approval October 25, 2026 04:18 — with GitHub Actions In progress

This branch is being deployed

1 in progress deployment
xks-remote-approval — f6e531ef Deployed Oct 25, 2026 by Manuthor via main / test / AWS XKS — remote server #9381
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant